I'm new to node.js and the Mocha framework for unit testing, but I created a couple of tests in the cloud9 IDE to see how it works. The code is as follows:
var assert = require("assert"); require("should"); describe('Array', function(){ describe('#indexOf()', function(){ it('should return -1 when the value is not present', function(){ assert.equal(-1, [1,2,3].indexOf(5)); assert.equal(-1, [1,2,3].indexOf(0)); }); }); }); describe('Array', function(){ describe('#indexOf()', function(){ it('should return the index when the value is present', function(){ assert.equal(1, [1,2,3].indexOf(2)); assert.equal(0, [1,2,3].indexOf(1)); assert.equal(2, [1,2,3].indexOf(3)); }); }); });
Testing works if I find mocha in the console, but the IDE shows warnings in the lines where “describe” and “this” because it says that the variable has not been declared (“undeclared variable”).
It is interesting that I do these tests to avoid warnings.
Thanks.
source share