I am starting out with Jest unit testing. I keep getting "No tests found" while running a jest unit test.
Error description
yarn test
yarn run v1.3.2
$ jest
No tests found
In E:\Course\Testing JavaScript\Jest Demo
4 files checked.
testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 3 matches
testPathIgnorePatterns: \\node_modules\\ - 4 matches
Pattern: - 0 matches
error Command failed with exit code 1.
os : window 7 , node v : 8.6, npm v : 5.4.2
folder structure :
Demo
package.json
__tests__
sum.js
sum.test.js
sum.js file:
function sum(a, b) {
return a + b;
}
module.exports = sum;
sum.test.js
const sum = require("./sum");
test("adds 1 + 2 to equal 3", () => {
expect(sum(1, 2)).toBe(3);
});
package.json
{
"name": "JestDemo",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"jest": "^22.4.3"
},
"scripts": {
"test": "jest"
}
}
So far, i have referred these articles Stackoverflow-Jest No Tests found
A few more post on github too regarding the same issue but nothing helped.
What i did so far :
1) changed the script to point to folder containing test files:
"scripts": {
"test": "jest __test__" //
from "test": "jest"
}
2) tried changing folder structure.
Could someone help me figure out the problem ?