Skip to content

Instantly share code, notes, and snippets.

@kerimdzhanov
Last active July 6, 2016 23:52
Show Gist options
  • Save kerimdzhanov/43af8d8a53489b2a4caeee40a9d9cc66 to your computer and use it in GitHub Desktop.
Save kerimdzhanov/43af8d8a53489b2a4caeee40a9d9cc66 to your computer and use it in GitHub Desktop.
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