denislexic
denislexic

Reputation: 11392

Jest ignore Cypress test

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)?

Upvotes: 16

Views: 6398

Answers (2)

Youssef Egla
Youssef Egla

Reputation: 1601

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/"],
}

Upvotes: 35

denislexic
denislexic

Reputation: 11392

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?$"

Upvotes: 3

Related Questions