我不知道为什么测试运行器不会检测到我的测试。
npm test
myproject@1.0.0 test C:\Users\sjsui\Desktop\git_workshop\myproject
mocha ./built/source
0 passing (4ms)
PS C:\Users\sjsui\Desktop\git_workshop\myproject>
我知道 test
是 mocha 搜索的默认文件夹,所以这就是我构建项目的方式。
built
\--source
\--test
\--test.js
这是我的 test.js 文件
describe("consumer tests", function()
{
it("runs bad request tests", (done) => {
let tests = new badrequesttests()
iteratebadtests(tests, done)
})
it("normal consumer tests", (done) => {
let tests = new normaltests()
iteratenormaltests(tests, done)
})
it("abnormal consumer tests", (done) => {
let tests = new unauthorizedtests()
iterateunauthorizedtests(tests, done)
})
})
package.json 中的 npm 脚本部分
"scripts": {
"test": "mocha ./built/source"
},
作为旁注,断点不会在测试中命中(visual studio code debug task -> mocha)
最佳答案
我认为您的测试脚本未被 mocha 检测到,因为默认情况下 mocha 不扫描子目录,并且您的测试位于您在调用 mocha 时传递的路径的子目录中。有两种方法可以解决这个问题。
如下提供测试文件夹到mocha的路径
mocha ./built/source/test
使用递归标志触发 mocha 测试。使用此标志 mocha 将扫描您提供的路径的子目录
mocha ./built/source --recursive
我认为这应该可以解决您的问题
关于node.js - 未找到 Mocha 测试 : "0 passing",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51998020/