My node. js learning path (iv) unit testing

  • 2020-03-30 03:30:07
  • OfStack

Installation through NPM:

NPM install nodeunit - g

./ glob. js is a local global variable file, now we use NodeUnit to test the above code node.js code:


var utils=new require('./utils.js');
this.TestForUtils = {
'TestgetGuid': function (test) {
var guid=utils.utils.getGuid();
test.ok(!!guid, 'getGuid should not be null.');
test.done();
},
'TestWritelog': function (test) {
var flag=false;
utils.utils.writeLog("test message");
flag=true;
test.ok(flag,'writeLog');
test.done();
},
'TestStartWithWords': function (test) {
var name="ad_123";
test.ok(utils.utils.startWith(name, "ad_"),"startwith method should be ok");
test.done();
}
};

Test.ok is also commonly referred to as an assertion. For NodeUnit's unit test program, you can also use the node-inspector to debug it


Related articles: