Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest No Tests found

running docker mhart/alpine-node:8 on macOS with

nodejs (6.10.3-r0) (18/18) yarn 0.24.6 jest 20.0.4

I have a __tests__/index.test.js file however, when running the code

node_modules/.bin/jest --watchAll I get the below output

No tests found
In /usr/src/app
5 files checked.
testMatch: /__tests__//*.js?(x),**/?(*.)(spec|test).js?(x) - 1 match
testPathIgnorePatterns: /node_modules/,/src,src - 0 matches
Pattern: "" - 0 matches

I've re-installed the package numbers times but to no avail.

like image 635
KArneaud Avatar asked Jun 24 '17 23:06

KArneaud


People also ask

Can you use Jest without node?

To read TypeScript configuration files Jest requires ts-node . Make sure it is installed in your project.

Do Jest tests run in a browser?

The answer is down to Jest not being a real browser. You have access to all of the various DOM APIs when writing Jest tests but these are provided by JSDOM and your tests are actually running in Node. Jest has no native way to run your tests in a browser environment out of the box.


2 Answers

Your output says that testMatch had 1 match, which may be your __tests__/index.test.js file. It seems that your testPathIgnorePatterns is causing that test suite to be ignored. No tests found In /usr/src/app says that Jest is looking for tests in /usr/src/app, and testPathIgnorePatterns: /node_modules/,/src,src says that Jest is ignoring files in /src directories.

Either point Jest to look at the location of your __tests__/index.test.js file if it is outside the /src directory, or stop testPathIgnorePatterns from ignoring the /src directory.

like image 114
Zachary Ryan Smith Avatar answered Sep 20 '22 19:09

Zachary Ryan Smith


If you have file structure such as the following

myFolder │   myFile1.js │   myFile2.js │   ... │    └───__tests__         myFile1.spec.js         myFile2.spec.js         ... 

then you need to have in jest.config.js the following pattern for testMatch property:

testMatch: ['**/__tests__/*.js?(x)'], 

The simple example of jest.config.js:

const jestConfig = {   verbose: true,   testURL: "http://localhost/",   'transform': {     '^.+\\.jsx?$': 'babel-jest',   },   testMatch: ['**/__tests__/*.js?(x)'], }  module.exports = jestConfig 
like image 34
Roman Avatar answered Sep 21 '22 19:09

Roman