node-assertthat provides a fluent TDD style for Node.js: assert.that(actual, is.equalTo(expected));
node-assertthat provides a fluent TDD style for Node.js:
$ npm install node-assertthat
Using node-assertthat is easy. All you need to do is to add a reference to it within your Node.js application:
var assert = require'node-assertthat';
Now you are able to use the various constraints:
varreturn first + second;;var actual = add23 42expected = 65;assertthatactual isequalToexpected;
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.
Please note that any constraint can be negated using the
actual is greater than or equal to
assertthatactual isatLeastexpected;assertthatactual isnotatLeastexpected;
actual is less than or equal to
assertthatactual isatMostexpected;assertthatactual isnotatMostexpected;
actual is between
assertthatactual isbetweenexpectedLow expectedHigh;assertthatactual isnotbetweenexpectedLow expectedHigh;
actual is equal to
assertthatactual isequalToexpected;assertthatactual isnotequalToexpected;
actual is false.
assertthatactual isfalse;assertthatactual isnotfalse;
actual is falsy.
assertthatactual isfalsy;assertthatactual isnotfalsy;
actual is greater than
assertthatactual isgreaterThanexpected;assertthatactual isnotgreaterThanexpected;
actual is an instance of
assertthatactual isinstanceOfexpected;assertthatactual isnotinstanceOfexpected;
actual is less than
assertthatactual islessThanexpected;assertthatactual isnotlessThanexpected;
actual is NaN.
assertthatactual isNaN;assertthatactual isnotNaN;
actual is null.
assertthatactual isnull;assertthatactual isnotnull;
actual is of type
assertthatactual isofTypeexpected;assertthatactual isnotofTypeexpected;
actual is identical to
assertthatactual issameAsexpected;assertthatactual isnotsameAsexpected;
f throws an exception.
assertthatf isthrowing;assertthatf isnotthrowing;
Alternatively, asserts that
f throws an exception with the
assertthatf isthrowingexpected;assertthatf isnotthrowingexpected;
actual is true.
assertthatactual istrue;assertthatactual isnottrue;
actual is undefined.
assertthatactual isundefined;assertthatactual isnotundefined;
This module can be built using Grunt. Besides running the tests, this also analyses the code. To run Grunt, go to the folder where you have installed node-assertthat and run
grunt. You need to have grunt-cli installed.
The MIT License (MIT) Copyright (c) 2011-2014 the native web.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.