Mocha 测试抛出 AssertionError

Mocha testing throws AssertionError

我正在使用 mocha 和 coffeescript 编写一个简单的测试脚本。

在我的测试文件夹中,我有一个 mocha 的配置(mocha.opts):

--compilers coffee: coffee-script/register
--reporter spec

还有我的测试文件(test_one.coffee):

assert = require "assert"

describe "A feature", ->
    describe "An specific function", ->
        it "Should work as expected", ->
            assert true

但每当我 运行 "mocha ." 它 returns 我这个:

assert.js:93

 throw new assert.AssertionError({ 

 AssertionError: missing path
     at Module.require (module.js:363:3)
     at require (module.js:380:17)
     at args (C:\...\AppData\Roaming\npm\node_modules\mocha\bi
     at Array.forEach (native)
     at Object.<anonymous> (C:\...\AppData\Roaming\npm\node_mo
     at Module._compile (module.js:456:26)
     at Object.Module._extensions..js (module.js:474:10)
     at Module.load (module.js:356:32)
     at Function.Module._load (module.js:312:12)
     at Function.Module.runMain (module.js:497:10)
     at startup (node.js:119:16)
     at node.js:929:3

关于如何解决这个问题的任何想法?

传递给 Mocha 的选项是:--compilers coffee:coffee-script/register。请注意冒号后缺少 space。

我相信发生的事情是 space,它告诉 Mocha 要编译 coffee 文件,它应该加载一个路径为空字符串的模块,然后你得到你得到的错误。

作为寻找此错误的任何人的参考。

这几乎总是传入字符串的错误package.json 我的是:

"test": "mocha --reporter spec --compilers ts:ts-node/register, 'test/**/*.test.ts'"

注意单词 register

后面的逗号