Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest ignore Cypress test

Tags:

jestjs

cypress

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

like image 625
denislexic Avatar asked Nov 11 '20 18:11

denislexic


2 Answers

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/"],
}
like image 58
Youssef AbouEgla Avatar answered Oct 05 '22 23:10

Youssef AbouEgla


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?$"
like image 22
denislexic Avatar answered Oct 05 '22 23:10

denislexic