April 2018
Intermediate to advanced
298 pages
6h 34m
English
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 ...