O'Reilly logo

React 16 Tooling by Adam Boduch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Values in collections

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required