我将要开始使用Jest进行单元测试。 运行Jest单元测试时一直提示“未找到测试”。
错误描述
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.
操作系统:Windows 7, Node.js版本:8.6, npm版本:5.4.2
folder structure :
Demo
package.json
__tests__
sum.js
sum.test.js
sum.js文件:
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"
}
}
到目前为止,我已经参考了这些文章:Stackoverflow-Jest找不到测试。还在GitHub上看了几篇有关相同问题的帖子,但没有什么帮助。
目前为止我所做的是:
1) 更改脚本指向包含测试文件的文件夹:
"scripts": {
"test": "jest __test__" //
from "test": "jest"
}
2) 尝试更改文件夹结构。
能有人帮我找出问题吗?
/tests
文件夹中的所有测试移动。 - sensorario