Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Chai.js expectations cheatsheet
// instead of using `expect(object).to.exist`, assert things
// through `.to.be.a(type)` which make failures more informative
expect(result).to.be.an('object')
.that.includes({
foo: 'bar',
baz: 'quux'
});
// to assert property value types i.e. date:
expect(result)
.to.have.property('createdAt')
.that.is.a('date');
// to assert errors:
expect(err).to.be.an('error')
.with.property('message', 'Oops!');
// to assert promises (thenable):
expect(result)
.to.be.an('object')
.with.property('then')
.that.is.a('function');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.