Skip to Content
React 16 Tooling
book

React 16 Tooling

by Adam Boduch, Christopher Pitt
April 2018
Intermediate to advanced content levelIntermediate to advanced
298 pages
6h 34m
English
Packt Publishing
Content preview from React 16 Tooling

Value equality

When working with objects and arrays, checking for equality can be painful. You typically can't use strict equality because you're comparing references, which are always different. If it's the values that you're trying to compare, you need to iterate over the object or collection and compare the values, keys, and indexes individually.

Since no one in their right mind wants to do all of this work to perform a simple test. Jest provides the toEqual() method, which compares object properties and array values for you:

describe('value equality', () => { 
  it('objects are the same', () => { 
    expect({ 
      one: 1, 
      two: 2 
    }).toEqual({ 
      one: 1, 
      two: 2, 
    });    expect({ 
      one: 1, 
      two: 2 
    }).not.toBe({ 
      one: 1, 
      two: 2 }); }); it('arrays are the same', ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro React 16

Pro React 16

Adam Freeman

Publisher Resources

ISBN: 9781788835015Supplemental Content