我正在尝试运行 Mocha 测试,例如,在 Node 程序中触发了一个事件。我试图避免使用 child_process
。看完this wiki 页面,我设置我的代码如下:
var Mocha = require("mocha");
var Reporter = require("./reporter");
var mocha = new Mocha({
ui: "tdd",
reporter: "spec"
});
mocha.addFile("test.js");
mocha.run();
test.js
有一个有效的 mocha 测试。但是当我运行它时,我不断收到 ReferenceError: describe is not defined
。为什么会这样? (当我在 Google 上搜索这个问题时,大多数解决方案都是关于使用 node 而不是 mocha 运行 test.js
的人。)
最佳答案
The BDD interface provides describe(), context(), it(), specify(), before(), after(), beforeEach(), and afterEach().
您已将 ui 设置为“tdd”:
The TDD interface provides suite(), test(), suiteSetup(), suiteTeardown(), setup(), and teardown():
关于node.js - 从 Node 运行 Mocha 测试 - 'describe' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37889078/