nodejs mocha suite未定义错误 [英] nodejs mocha suite is not defined error
本文介绍了nodejs mocha suite未定义错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用mocha运行一些测试,但似乎无法克服此错误。
I am trying to run some tests using mocha but cant seem to get over this error.
E:\tdd\nodejs\cart>mocha cart.test.js
node.js:201
throw e; // process.nextTick error, or 'err
^
ReferenceError: suite is not defined
at Object.<anonymous> (E:\tdd\nodejs\cart\cart.test.js:5:1
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at C:\Users\lex\AppData\Roaming\npm\node_module
at Array.forEach (native)
at load (C:\Users\lex\AppData\Roaming\npm\node_
9)
at Object.<anonymous> (C:\Users\lex\AppData\Roa
in\_mocha:237:1)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array.0 (module.js:470:10)
at EventEmitter._tickCallback (node.js:192:40)
从调用堆栈中我可以看出p roblem在这里 cart.test.js:5:1
。
知道是什么导致了这个吗?
From what I can tell from the call stack the problem is here cart.test.js:5:1
.
Any idea what is causing this ?
谢谢
cart.js
var GetTotalSum = function (input) {
var total = 0,
differentTitles = 0,
discountMap = [0, 1, 0.95, 0.9, 0.8, 0.75],
BOOK_PRICE = 8;
for (var i in input) {
total += input[i] * BOOK_PRICE;
if (input[i] > 0) {
differentTitles++;
}
}
if (differentTitles > 1) {
total = total * discountMap[differentTitles];
}
return total;
}
module.exports.GetTotalSum = GetTotalSum;
cart.test.js
var assert = require('assert'),
cart = require('./cart.js');
suite('cart', function () {
test('buy one book', function () {
// Arrange
var input = [1, 0, 0, 0, 0],
expected = 8;
// Act
var actual = cart.GetTotalSum(input);
// Assert
assert.equal(actual, expected);
});
});
推荐答案
你需要告诉Mocha使用TDD接口,而不是默认的BDD:
You need to tell Mocha to use the TDD interface, instead of the default BDD one:
mocha --ui tdd card.test.js
这篇关于nodejs mocha suite未定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文