I have a create-react-app
app and used to use jest
for testing but I'm slowly migrating to cypress
.
The thing is, now when I run my jest
tests, it includes my cypress
tests and gives an error
ReferenceError: Cypress is not defined
How can I make it that my jest
(naming convention *.test.js
) test ignore my cypress
test (which are usually called *.spec.js
)?
You should use testPathIgnorePatterns
in your jest config.
An array of regexp pattern strings that are matched against all test paths before executing the test. If the test path matches any of the patterns, it will be skipped.
According to Jest config docs
jest.config.js
module.exports = {
// Your normal jest config settings
testPathIgnorePatterns: ["<rootDir>/cypress/"],
}
In your jest/config.js
or wherever you have your jest config (could be package), add the following to replace the default regex to find tests from
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$"
to:
"testRegex": "(/__tests__/.*|(\\.|/)(test))\\.[jt]sx?$"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With