The things to consider for analyze the pros and cons of each framework are:
Syntax is simple:
import test from 'ava'; test('arrays are equal', t => {t.deepEqual([1, 2], [1, 2]);
}); To run only a specific test, use the.only
modifier:
test.only('will be run', t => {
t.pass();});
describe("A suite is just a function", function() {
var a;it("and so is a spec", function() {
a = true;expect(a).toBe(true);
});});
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.
var assert = require('assert');
describe('Array', function() {describe('
assert.equal([1,2,3].indexOf(4), -1);
});});
});Mocha does not have a built in assertion library.
hapijslab is a simple test utility for Node.js. Unlike other test utilities, lab uses only async/await features and includes everything you should expect from a modern Node.js test utility. Our goal with lab is to keep the execution engine as simple as possible, and not try to build an extensible framework.
lab works with any assertion library that throws an error when a condition isn't met.Sometimes it could be hard to trace the failures in large tests. The reporting format is:
[Checkmark or -] testNumber) test description
A minus sign would mean that the test case has been marked with skip
.
So, to search and highlight the failures, you could use the following regexp:
/- [0-9]
To skip a single test, you can change the it
expression to:
it.skip('test case'
If you would like to select only 1 test case and turn everything else off, use
it.only('test case'
\s[0-9]*)\s
Also since lab will always report the time spent running the test at the end, you can search for:
Test duration:\s
node-tap Has a command line interface for running tests and reporting on their success or failure. Also supports test coverage and running tests in parallel.
It has built-in assertion libraries such as:
t.ok(obj, message, extra)
t.ok(obj, message, extra) See tap assertions for more info.The output is a bit difficult to decipher when the tests get large. The easiest way to track down the errors is to look for test groups that dont have the full number of tests run. i.e.
tests/myTest.js ..... 18/19
would indicate an error while
tests/myTest.js ..... 19/19
would indicate success.
..... [numbers]
So the regex, would be
/\.\.\. [0-9]
Standalone test spies, stubs and mocks for JavaScript. Works with any unit testing framework. It provides Spies, Stubs, Mocks, Fake timers, Fake XHR and server, JSON-P, Assertions, Matchers, Sandboxes, Utils.
var callback = sinon.spy();
var proxy = once(callback);proxy();
assert(callback.called);Chai has several interfaces that allow the developer to choose the most comfortable. The chain-capable BDD styles provide an expressive language & readable style, while the TDD assert style provides a more classical feel
chai.should();
foo.should.be.a('string'); var expect = chai.expect;expect(foo).to.be.a('string');
var assert = chai.assert;
assert.typeOf(foo, 'string');assert.equal(foo, 'bar');
tap assertions: http://www.node-tap.org/asserts/
hapijslab: https://github.com/hapijs/labnode-tap: http://www.node-tap.org/