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

Approximate equality

There are times where checking for the exact value of something in your code makes no difference and could be more work than is worthwhile. For example, you might only need to make sure that a value is present. You might also need to perform the inverse—to make sure that there is no value. Something versus nothing in JavaScript terminology is truthy versus falsy.

To check for truthy or falsy values in your Jest unit tests, you would use the isTruthy() or isFalsy() methods respectively:

describe('approximate equality', () => { 
  it('1 is truthy', () => { 
    expect(1).toBeTruthy(); 
    expect(1).not.toBeFalsy(); 
  }); 
 
  it('\'\' is falsy', () => { 
    expect('').toBeFalsy(); 
    expect('').not.toBeTruthy(); 
  }); 
});

The value 1 isn't true, but ...

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