Mocha is the most popular unit testing platform, but I donβt like it very much because the error parameter must be an Error object, for example, you cannot pass an array of errors. Tap and should.js are also very good.
If you do not need all the functions of these frameworks, you can create your own using the built-in assert module. No dependencies, no bloated code, just a few lines, easy.
var tests = { "description 1": function (done){ testSomethingAsync (function (error){ assert.ifError (error); //assert other things done (); }); }, "description 2": function (){ var res = testSomethingSync (); //assert other things } }; var keys = Object.keys (tests); var keysLength = keys.length; (function again (i){ if (i<keysLength){ var fn = tests[keys[i]]; if (fn.length){ fn (function (){ again (i + 1); }); }else{ fn (); again (i + 1); } } })(0);
source share