April 2018
Intermediate to advanced
298 pages
6h 34m
English
There are way more assertion methods available in Jest than I have room to cover in this book. I encourage you to take a look at the Expect section of the Jest API docs: https://facebook.github.io/jest/docs/en/expect.html.
The last two assertion methods I want to go over with you are toHaveProperty() and toContain(). The former tests that an object has a given property while the latter checks that an array contains a given value:
describe('object properties and array values', () => {
it('object has property value', () => {
expect({
one: 1,
two: 2
}).toHaveProperty('two', 2);
expect({
one: 1,
two: 2
}).not.toHaveProperty('two', 3);
}); it('array contains value', () => { expect([1, 2]).toContain(1); expect([1, 2]).not.toContain(3); ...