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 the equal and property assertions

1
expect(foo).to.deep.equal({bar: 'bar'})

any

set the any flag, (opposite of the all flag), later used in the keys assertion

1
expect(foo).to.have.any.keys('bar', 'foo')

all

set the all flag, (opposite of the any flag), later used by the keys assertions

1
expect(foo).to.have.all.keys('bar', 'foo')

a(type)

  • @param {String} type
  • @param {String} message [optional]

The a and an assertion are aliases that can be used either as language chains or to assert a value’s type

1
2
3
4
// typeof
expect('test').to.be.a('string')
// language chain
expect(foo).to.be.an.instanceof(Foo)

include(value)

  • @param {Object | String | Number} obj
  • @param {String} message [optional]

The include and contain 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
2
3
expect([1,2,3]).to.include(2)
expect('foobar').to.contain('foo')
expect({ foo: 'foo', bar: 'bar' }).to.include.keys('foo')

ok

Assert that the target is truthy

1
2
expect('everything').to.be.ok
expect(undefined).to.not.be.ok

true

Assert that the target is true

1
2
expect(true).to.be.true
expect(1).to.be.true

false

Assert that the target is false

1
2
expect(false).to.be.false
expect(0).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 nor undefined

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
2
3
function test () {
expect(arguments).to.be.arguments
}

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 to value

1
2
expect('hello').to.equal('hello')
expect({foo: 'foo'}).to.deep.equal({foo: 'foo'})

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
2
3
4
5
6
7
var Tea = function (name) {
this.name = name,
}
var Chai = new Tea('chai')

expect(Chai).to.be.an.instanceof(Tea)
expect([1,2,3]).to.be.an.instanceof(Array)

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 to value. If the deep flag is set, you can use dot- and bracket-notation for deep reference into objects and arrays.

1
2
expect(obj).to.have.property('foo')
expect(obj).to.have.property('foo', 'bar')

to be continued