javascript - Unit.js , Mocha example.js 失败 0 通过

标签 javascript node.js unit-testing mocha.js

我刚刚用 mocha 学习 Unit.js。我正在按照以下步骤操作:http://unitjs.com/guide/quickstart.html 。我已经安装了 mocha 并正在运行“example.js”脚本。脚本失败并显示

$ Mocha 示例.js

0 通过(1 毫秒)

使用 -full-trace 运行 example.js 我得到:

$ mocha example.js -full-trace

C:\Users\rball\AppData\Roaming\npm\node_modules\mocha\lib\utils.js:652
        throw new Error("cannot resolve path (or pattern) '" + path + "'");
        ^

Error: cannot resolve path (or pattern) '-t'
    at Object.lookupFiles (C:\Users\rball\AppData\Roaming\npm\node_modules\mocha\lib\utils.js:652:15)
    at C:\Users\rball\AppData\Roaming\npm\node_modules\mocha\bin\_mocha:326:30
    at Array.forEach (native)
    at Object.<anonymous> (C:\Users\rball\AppData\Roaming\npm\node_modules\mocha\bin\_mocha:325:6)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:134:18)
    at node.js:961:3

我正在使用 cygwin64 运行它。并在目录中运行:/home/rball/test

example.js 是:

// load Unit.js module
var test = require('../node_modules/unit.js');
// just for example of tested value
var example = 'hello';
// assert that example variable is a string
test.string(example);
// or with Must.js
test.must(example).be.a.string();
// or with assert

unit.js 位于node_modules 目录中。

完整跟踪输出中的错误令人困惑,因为我不知道其中有任何带有“-t”的路径。

我错过了什么?

感谢您的帮助

最佳答案

我认为你需要在“-full-trace”前面添加一个额外的“-”。

示例:'--full-trace'

您使用“test.string(example)”设置断言器。您已经向它传递了指定的变量类型,如果您要验证字符串值、长度等,那就没问题了。

试试这个: '测试.value(示例).isString();' - - 或者 - - 'test.value(example).must.be.a.string();'

http://unitjs.com/api/value.html#isString

关于javascript - Unit.js , Mocha example.js 失败 0 通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39478273/

相关文章:

javascript - 在 react-native-maps 中渲染多个标记

javascript - 为什么事件在 Firefox 中未定义?

node.js - 如何直接将 Web 服务与 bot 框架通信?

node.js - 使用 sequelize 迁移将关联添加到非默认模式

javascript - Chai 希望 .to.throw(Error) 无法按预期工作

javascript - 如何在 Google Maps InfoWindow 中创建 CSS 样式的 dom 元素?

javascript - 光标在输入标签中不起作用

javascript - 在javascript中将复杂类型的字符串数组转换为json

c# - 如何在测试类(ASP.NET Core)中注入(inject)配置设置?

c# - 单元测试和 Entity Framework