笑话显示0测试共2

问题描述

使用节点配置Jest之后,我可以无错误地运行测试,但是我会得到这样的输出

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

即使我有一个测试文件,但它不会使它失败或通过

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

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

配置文件

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

脚本

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

命令

npm run test

Jest Install命令

npm install jest@22.2.2

如何开始获得正确的结果?

解决方法

您可以尝试此解决方案,将配置文件扩展为.js。
jest.config.js

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

脚本

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

sum.js

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

__测试__ / sum.test.js

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

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...