如何解决笑话显示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);
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。