Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run jest files that have no .test. in their filename?

Tags:

jestjs

I have some tests that are ment to be run aside from all other .test files so I called them .integration.js

how to test all files that have .integration.js?

example file; endpoint.integration.js

like image 362
Tree Avatar asked Oct 18 '18 19:10

Tree


People also ask

How do I run a Jest test for a specific file?

In order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli . Then simply run your specific test with jest bar.

How do you run only one describe in Jest?

only and describe. only work only for the module they are in. If you are having problems to filter tests in multiple files, you can use jest -t name-of-spec , filtering tests that match the specified name (match against the name in describe or test).


1 Answers

You can configure custom test file names with the config key testRegex. https://jestjs.io/docs/en/configuration#testregex-string--arraystring

The default is: (/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$

So to only run tests in files like endpoint.integration.js tests, you can use this regex instead: \\.integration\\.js$

You can put this in your configuration either in package.json or jest.config.js.

Or you can use the regex as the first argument to the jest cli command.

jest '\\.integration\\.js$'
like image 89
Håken Lid Avatar answered Sep 30 '22 15:09

Håken Lid