May 2019
Intermediate to advanced
496 pages
10h 38m
English
There is a school of thought that checking for null in tests is redundant and can be removed all together. In other words, the second-to-last test we wrote would become this:
it('renders a label for the first name field', () => { render(); expect(labelFor('firstName').textContent).toEqual('First name');});
In the original test, the first not null expectation is a guard expectation. The test will still function even without this line, since the second expectation will throw an exception if the value of label is null.
The run-time difference between the two variants of the test is subtle. The original test will fail with a test failure, not an exception. In this second version, your test will fail with an exception, ...
Read now
Unlock full access