【发布时间】:2018-09-10 01:57:44
【问题描述】:
我从 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.
os : 窗口 7 , 节点 v:8.6, npm v: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 No Tests found
关于相同问题的更多帖子也在 github 上,但没有任何帮助。
到目前为止我做了什么:
1) 将脚本更改为指向包含测试文件的文件夹:
"scripts": {
"test": "jest __test__" //
from "test": "jest"
}
2) 尝试更改文件夹结构。
有人可以帮我解决问题吗?
【问题讨论】:
-
移动
/tests文件夹中的所有测试 -
@sensorario - 这行得通。在所有正式文档中,tests 被提及为默认文件夹,但它对我不起作用。您应该将其作为答案发布的评论。我会接受这个作为答案
-
我已经用我的配置更新了我的答案。希望这能有所帮助。
标签: javascript unit-testing jestjs