Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
110
rated 0 times [  114] [ 4]  / answers: 1 / hits: 16064  / 12 Years ago, tue, march 20, 2012, 12:00:00

I am trying to run some tests using mocha but cant seem to get over this error.



E:tddnodejscart>mocha cart.test.js

node.js:201
throw e; // process.nextTick error, or 'err
^
ReferenceError: suite is not defined
at Object.<anonymous> (E:tddnodejscartcart.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:UserslexAppDataRoamingnpmnode_module
at Array.forEach (native)
at load (C:UserslexAppDataRoamingnpmnode_
9)
at Object.<anonymous> (C:UserslexAppDataRoa
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)


From what I can tell from the call stack the problem is here cart.test.js:5:1.
Any idea what is causing this ?



Thanks



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);
});
});

More From » node.js

 Answers
29

You need to tell Mocha to use the TDD interface, instead of the default BDD one:



mocha --ui tdd card.test.js

[#86712] Monday, March 19, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anders

Total Points: 295
Total Questions: 106
Total Answers: 104

Location: Angola
Member since Wed, Apr 13, 2022
2 Years ago
;