Sink Test
An Asynchronous JavaScript Unit Testing Framework designed to run headless, or in the browser.
Sink test is used to test JavaScript that is run asynchronously whereby you can specify the number of expectations and Sink will tell you if they each pass successfully or call an optional complete()
callback to indicate test completion.
How to write a Sink test
// alternatively:
Loading a suite of tests
The above example illustrates the basic syntax of a single test, however loading your tests is done via the sink module which exports the test and ok methods. See the example below:
// start all test modules
Browser support
Any browser that supports JavaScript as well as Headless via command line with Node. (see below)
// tests.jsvar sink =var start = sinkstartsink = sinksink
in your terminal
$ node path/to/my/tests.js
Advanced assertion support
Sink Test follows most of the assert module specified in the CommonJS Unit-Testing/1.0 assert module and gives you additional convenience assertions plus an API to define your own assertions.
Basic assert calls perform a strict equals:
; // performs: actual === expected
The assert
method is extended, giving you aliases for the above:
assert;assert;// and the inverse:assert;assert;
And also an alias for the simple boolean ok
method:
assert
A non-strict deep equals is available via:
assert;assert;// and the inverse:assert;
And many additional assertions to make your tests clear and obvious:
assert; // performs a "typeof value == type"assert;assert;assert;assert;assert;assert;assert;assert;assert;assert;assert;assert;assert;assert; // is the value a DOM element
The message parameter on all assertions is optional.
Custom assertions
When you have a complex condition to assert, you can define a custom assertion for it with the assert.add()
method.
Simply provide your assertion name and the handler function. Handler functions can take one or two arguments:
// single-argument form:assert;// use it:assert; // → failassert; // → pass// dual-argument form:assert;// use it:assert;
Happy testing!