Chains
- to
- be
- been
- is
- that
- which
- and
- has
- have
- with
- at
- of
- same
not
negative any of assertions following in the Chains
1 | expect(foo).to.not.equal('bar') |
deep
set the
deep
flag, later used by theequal
andproperty
assertions
1 | expect(foo).to.deep.equal({bar: 'bar'}) |
any
set the
any
flag, (opposite of theall
flag), later used in thekeys
assertion
1 | expect(foo).to.have.any.keys('bar', 'foo') |
all
set the
all
flag, (opposite of theany
flag), later used by thekeys
assertions
1 | expect(foo).to.have.all.keys('bar', 'foo') |
a(type)
- @param {String} type
- @param {String} message [optional]
The
a
andan
assertion are aliases that can be used either as language chains or to assert a value’s type
1 | // typeof |
include(value)
- @param {Object | String | Number} obj
- @param {String} message [optional]
The
include
andcontain
assertion can be used as either property based language chains or methods to assert the inclusion of an object in an array or a substring in a string.
1 | expect([1,2,3]).to.include(2) |
ok
Assert that the target is truthy
1 | expect('everything').to.be.ok |
true
Assert that the target is
true
1 | expect(true).to.be.true |
false
Assert that the target is
false
1 | expect(false).to.be.false |
null
Assert that the target to be
null
1 | expect(null).to.be.null |
undefined
Assert that the target is
undefined
1 | expect(undefined).to.be.undefined |
NaN
Assert that the target is
NaN
1 | expect('foo').to.be.NaN |
exist
Assert that the target is neither
null
norundefined
1 | expect('foo').to.be.exist |
empty
Assert that the target’s length is 0. For Array and String, it will check the length of propertes. For Object, it will check the length of enumerable keys
1 | expect([]).to.be.empty |
arguments
Assert that the target is an arguments object
1 | function test () { |
equal(value)
- @param {Mixed} value
- @param {String} message [optional]
Assert that the target is strictly equal(===) to
value
. Alternately, if the.deep
flag is set, assert that the target is deeply equal tovalue
1 | expect('hello').to.equal('hello') |
eql(value)
- @param {Mixed} value
- @param {String} message [optional]
1 | expect({foo: 'foo'}).to.eql({foo: 'foo'}) |
above(value)
- @param {Number} value
- @param {String} message [optional]
Assert that the target is greater than
value
1 | expect(10).to.be.above(5) |
Can also be used in conjunction with
length
to assert a minimum length.
1 | expect('foo').to.have.length.above(2) |
least(value)
- @param {Number} value
- @param {String} message [optional]
Assert that the target is greater than or equal to
value
1 | expect(10).to.be.at.least(10) |
used for length too
below(value)
- @param {Number} value
- @param {String} message [optinal]
Assert that the target is less than
value
1 | expect(5).to.be.below(10) |
used for length too
most(value)
- @param {Number} value
- @param {String} message [optinal]
Assert that the target is less than or equal to
value
1 | expect(5).to.be.at.most(5) |
used for length o
within(start, finish)
- @param {Number} start lowerbound inclusive
- @param {Number} finish upperbound inclusive
- @param {String} message [optional]
Assert that the target is within a range
1 | expect(28).to.be.within(2, 30) |
used for length too
instanceof(constructor)
- @param {Constructor} constructor
- @param {String} message [optional]
1 | var Tea = function (name) { |
property(name[, value])
- @param {String} name
- @param {Mixed} value [optional]
- @param {String} message [optional]
Assert that the target has a property
name
, optionally asserting that the value of that property is strictly equal tovalue
. If thedeep
flag is set, you can use dot- and bracket-notation for deep reference into objects and arrays.
1 | expect(obj).to.have.property('foo') |