8. Should.js
should is an expressive, readable, test
framework agnostic, assertion library.
Main goals of this library to be expressive
and to be helpful.
It keeps your test code clean, and your
error messages helpful.
9. Should.js
1 var should = require('should');
2
3 var user = { name: 'davide', pets: ['tobi', 'loki']};
4
5 user.should.have.property('name', 'davide');
6 user.should.have.property('pets').with.lengthOf(2);
7
8 should(user).have.property('name', 'davide');
9 should(true).ok;
10
11 should.exist(user);
It extends the Object.prototype with a single non-
enumerable getter that allows you to express how that
object should behave, also it returns itself when required
with require.
11. Should.js - Chaining
assertions
1 var should = require('should');
2
3 var user = { name: 'davide', age : 22};
4
5 user.age.should.be.greaterThan(18).and.be.lessThan(33);
6
7 user.age.should.greaterThan(18).lessThan(33);
.an, .of, .a,.and, .be, .have, .with, .is, .which
Use them for better readability; they do nothing at all