Questions
Answer the following questions to check what you have learned in this chapter:
- We have written some tests for a
HomePage
component and placed them in a file calledHomePage.tests.tsx
. However, the tests aren’t run when thenpm test
command is executed—not even when the a key is pressed to run all the tests. What do you think the problem might be? - Why doesn’t the following expectation pass? How could this be resolved?
expect({ name: 'Bob' }).toBe({ name: 'Bob' });
- Which matcher can be used to check that a variable isn’t
null
? - Here’s an expectation that checks whether a Save button is disabled:
expect(
screen.getByText('Save').hasAttribute('disabled')
).toBe(true);
The expectation passes as expected, but is there a different matcher that can be used to simplify this?
- Write a test for the
getNewCheckedIds
function we used in this chapter. The test should check...