node-assertthat provides a fluent TDD style for Node.js: assert.that(actual, is.equalto(expected));
$ npm install node-assertthat
Using node-assertthat is easy. All you need to do is to require it, and then use it:
var assert = require('node-assertthat');
var add = function(first, second) {
return first + second;
};
var actual = add(23, 42),
expected = 65;
assert.that(actual, is.equalTo(expected));Please note that node-assertthat extends Node's assert module, i.e. all the code you have been used to will work with node-assertthat as well.
That's it :-)!
Please note that all is functions can be negated using the not keyword.
Asserts that actual and expected share the same value.
assert.that(actual, is.equalTo(expected));
assert.that(actual, is.not.equalTo(expected));Asserts that actual and expected share the same reference, i.e. both refer to the same object.
assert.that(actual, is.sameAs(expected));
assert.that(actual, is.not.sameAs(expected));Asserts that actual is true.
assert.that(actual, is.true);
assert.that(actual, is.not.true);Asserts that actual is false.
assert.that(actual, is.false);
assert.that(actual, is.not.false);Asserts that f throws an error of type err.
assert.that(f, throws.an(err));Asserts that f does not throw an error of type err.
assert.that(f, doesNotThrow.an(err));node-assertthat is covered by unit tests that are based on Expresso. To run these tests, simply run
$ expresso
in the root folder of the module.
(c) Copyright 2011-2012 Golo Roden, contact using webmaster@goloroden.de