- Update all dependencies
- Break changes:
The native
Number()
is an object. Sotest.number(val)
andtest.value(val).isNumber()
consider the reality, an instance ofNumber()
is an object.
In should.js@v6 the behavior of should.containDeep*
was changed slightly. should.containDeep*
does not check substrings anymore.
See should.js#42
.contains() and .notContains() takes several arguments (instead of an array of arguments). This new behavior is more natural and avoids the ambiguity for test an array or object.
New methods of assertion:
- test.number(actual).isNaN()
- test.number(actual).isNotNaN()
- test.value(parseInt('not a number', 10)).isNaN()
- test.value(undefined).isNotNaN()
- Lots of sub-dependencies are removed.
- No break in the API.
- New features.
- Fanatically tested and documented.
Now we can use Unit.js in the browser ✊
So we can write unit tests with Unit.js for Web applications based on Vanilla JS, jQuery, AngularJS, Backbone.js, ReactJS ... all!
With any runner like Mocha, Jasmine, Protractor (end-to-end test framework for AngularJS applications), QUnit, ... what you want :)
To use Unit.js with Mocha simply install npm install -g mocha
and uses the command mocha <path/of/your/test/directory>
Or npm install mocha --save-dev
and add in your package.json
:
"scripts": {
"test": "mocha test"
}
Then uses this command npm test
.
See Mocha tutorial in the guide.
- isReverseOf()
- isNotReverseOf()
- isStrictEqualTo() alias of isIdenticalTo() (
===
) - isNotStrictEqualTo() alias of isNotIdenticalTo() (
!==
)
- test.promise
- test.promisify()
- test.promisifyAll()
- test.fail()
- test.stats
See helpers in the guide.
To keep execution flow organized, Unit.js integrates a mechanism of promise based on the excellent bluebird.
Bluebird is a fully featured promised library with focus on innovative features and performance.
Example:
var fs = test.promisifyAll(require('fs'));
fs.readFileAsync(require('path').resolve() + '/package.json')
.when(JSON.parse)
.then(function(pkg) {
test
.object(pkg)
.hasKey('name', 'unit.js')
.hasKey('version')
.value(pkg.version)
.isGreaterThan('1')
;
})
.catch(SyntaxError, function(err) {
test.fail('Syntax error');
})
.catch(function(err){
test.fail(err.message);
})
.done()
;
Given, when, then
are integrated on top of bluebird:
test.promise
.given($.get('http://www.google.com'))
.when(function(google) {
// some states
// contents = ...
return $.post('http://localhost/api');
})
.then(function(apiPost){
//some tests
})
.catch(function(error) {
// error handler (you can use test.fail() helper)
})
.done()
;
Useful for managing easily the control flow of asynchronous tests.
See promise in the guide.
Unit.js supports Dependency Injection (Inversion Of Control).
See dependency-injection in the guide.
Unit.js provides a plugins system (based on Noder.io) for extending Unit.js's assertions and interfaces.
It is possible to create a package works easily as a plugin for Unit.js and also as a standalone module or library.
If you wrote a plugin for Unit.js, please let us know.
See plugins tutorial in the guide.
Documentation has been improved.