node.js - 未找到 Mocha 测试 : "0 passing"

标签 node.js testing mocha.js

我不知道为什么测试运行器不会检测到我的测试。

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 时传递的路径的子目录中。有两种方法可以解决这个问题。

  1. 如下提供测试文件夹到mocha的路径

    mocha ./built/source/test
    
  2. 使用递归标志触发 mocha 测试。使用此标志 mocha 将扫描您提供的路径的子目录

    mocha ./built/source --recursive
    

我认为这应该可以解决您的问题

关于node.js - 未找到 Mocha 测试 : "0 passing",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51998020/

相关文章:

testing - 如何综合编译器测试数据?

reactjs - Mocha & Enzyme - 如何测试 React 组件没有子组件?

javascript - 找不到模块 express——在 Windows 上

javascript - 在查询中附加单引号 (' ' )

node.js - 使用 Pushstate 和 NodeJS

Azure 上的 Node.js 远程调试

ruby-on-rails-3 - Rspec 2 + Devise + Cancan - Factorygirl = Controller 测试不工作

perl - 使用 Perl LWP 欺骗 IP

node.js - 测试错误通过 Mocha 回调传回,应该

ruby-on-rails - 使用 Minitest stub any_instance