Zaid Iqbal
Zaid Iqbal

Reputation: 1692

Jest shows 0 test of 2 total

After the configuration of Jest with Node, I am able to run the tests with no errors but I am getting output like this

Test Suites: 0 of 2 total
Tests:       0 total
Snapshots:   0 total
Time:        0.508s
Ran all test suites.

even though I have a test file but it does not either make it fail or pass

const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

Config File

{
    "name": "my-project",
    "testMatch": [ "**/__tests__/**/*.[jt]s?(x)" ],
    "testPathIgnorePatterns": ["\\node_modules\\"]
}

Script

"test": "jest --config ./jest.config.json",

Command

npm run test

Jest Install command

npm install [email protected]

How can I start getting the correct result?

Upvotes: 1

Views: 599

Answers (1)

muthu
muthu

Reputation: 803

you can try this solution, make config file as .js extension.
jest.config.js

module.exports = {
    roots: ['./__tests__'], // provide path with reference to this modue, I assumed both are in root
  };

script

 "test": "jest --config='./jest.config.js'"

sum.js

function sum(num, num1){
return num+num1
}
exports.sum=sum

__tests __/sum.test.js

const sum = require('../sum');

test('adds 1 + 2 to equal 3', () => {
  expect(sum.sum(1,2)).toBe(3);
});

Upvotes: 1

Related Questions