Last active
July 6, 2016 23:52
-
-
Save kerimdzhanov/43af8d8a53489b2a4caeee40a9d9cc66 to your computer and use it in GitHub Desktop.
Chai.js expectations cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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