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

The toHaveProperty() method is useful when you need to check if an object has a particular property value. The toContain() method is useful when you need to check if an array has a particular value.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.23.130