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.
includeEql(obj)
Assert that an object equal to the given obj is present in an Array:
throw()
Assert an exception is thrown
throwError()
An alias of throw, its purpose is to be an option for those who run jshint in strict mode.
keys
Assert own object keys, which must match exactly, and will fail if you omit a key or two:
.and
Provide a AND relationship between asserts.
.have
Provides an assert requirement.
.have
Provides an assert requirement.
.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.
includeEql(obj)
Assert that an object equal to the given obj is present in an Array:
throw()
Assert an exception is thrown
throwError()
An alias of throw, its purpose is to be an option for those who run jshint in strict mode.
keys
Assert own object keys, which must match exactly, and will fail if you omit a key or two:
.and
Provide a AND relationship between asserts.
.have
Provides an assert requirement.