Should.js Assertions Flashcards
Chainable assertions for Should.js Testing Framework. https://github.com/visionmedia/should.js
.ok
Asserts true
.true
Assert === true:
.false
Assert === false:
.arguments
var args = (function(){ return arguments; })(1,2,3);
args.should.be.arguments;
[].should.not.be.arguments;
.empty
[].should.be.empty
‘‘.should.be.empty
({ length: 0 }).should.be.empty
.eql
Asserts equality
({ foo: ‘bar’ }).should.eql({ foo: ‘bar’ })
[1,2,3].should.eql([1,2,3])
equal
Strict Equality
should. strictEqual(undefined, value)
should. strictEqual(false, value)
(4) .should.equal(4)
‘test’.should.equal(‘test’)
[1,2,3].should.not.equal([1,2,3])
.within
Assert inclusive numeric range:
user.age.should.be.within(5, 50)
.a(‘typeof’)
Asserts typeof
user.should.be.a(‘object’)
‘test’.should.be.a(‘string’)
instanceof
user.should.be.an.instanceof(User)
[].should.be.an.instanceOf(Array)
.above( int )
Assert numeric value above the given value:
user. age.should.be.above(5)
user. age.should.not.be.above(100)
.below( int )
Assert numeric value below the given value:
.match
Assert regexp match:
username.should.match(/^\w+$/)
.length( int )
Assert length property exists and has a value of the given number:
user. pets.should.have.length(5)
user. pets.should.have.a.lengthOf(5)
.property
Assert property exists and has optional value:
user. should.have.property(‘name’)
user. should.have.property(‘age’, 15)
user. should.not.have.property(‘rawr’)
user. should.not.have.property(‘age’, 0)
.ownProperty
Asserts own property.
.status(code)
Assets status code is ###.
.header(field[, value])
Asserts that a .headers object with field and optional value are present:
.json
Assert that Content-Type is “application/json; charset=utf-8”
.html
Assert that Content-Type is “text/html; charset=utf-8”
include(obj)
Assert that the given obj is present via indexOf(), so this works for strings, arrays, or custom objects implementing indexOf.