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

Basic equality

You can assert that two values are the same by using the toBe() expectation method:

describe('basic equality', () => { 
  it('true is true', () => { 
    expect(true).toBe(true); 
    expect(true).not.toBe(false); 
  }); 
 
  it('false is false', () => { 
    expect(false).toBe(false); 
    expect(false).not.toBe(true); 
  }); 
}); 

In the first test, you're expecting true to equal true. Then, you're negating this expectation in the next line using the .not property. If this were a real unit test, you wouldn't have to prove the opposite of an assertion that you've just made like this—I'm doing this to illustrate some of your options.

In the second test, we're performing the same assertions but with false as the expectation value. The toBe() method uses strict ...

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