【问题标题】:Mocha testing throws AssertionErrorMocha 测试抛出 AssertionError
【发布时间】:2015-06-27 20:21:00
【问题描述】:

我正在使用 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”时。它返回给我:

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

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

【问题讨论】:

    标签: javascript node.js coffeescript mocha.js assert


    【解决方案1】:

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

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

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

    注意单词register

    后面的逗号

    【讨论】:

      【解决方案2】:

      传递给 Mocha 的选项是:--compilers coffee:coffee-script/register。注意冒号后面没有空格。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-02
        • 2016-08-03
        • 2012-09-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多