Answers
- The problem is that the file extension is
tests.tsx
rather thantest.tsx
. - The
toBe
matcher should only be used for checking primitive values such as numbers and strings—this is an object. ThetoStrictEqual
matcher should be used to check objects because it checks the values of all its properties instead of the object reference:expect({ name: 'Bob' }).toStrictEqual({ name: 'Bob' });
- The
not
andtoBeNull
matchers can be combined to check a variable isn’tnull
:expect(something).not.toBeNull();
- The
toBeDisabled
matcher can be used fromjest-dom
:expect(screen.getByText('Save')).toBeDisabled();
- Here’s a test:
test('should remove id when already in checked ids', () => {
const result = getNewCheckedIds([1, 2, 3], 2);
expect(result).toStrictEqual([1, 3]);
});
- The
findBy
query type requires awaiting because it is asynchronous:expect(await screen.findByText('Save')).toBeInTheDocument...