I've found a lot of this sort of thing when refactoring our Jest test suites:
it('calls the API and throws an error', async () => {
expect.assertions(2);
try {
await login('email', 'password');
} catch (error) {
expect(error.name).toEqual('Unauthorized');
expect(error.status).toEqual(401);
}
});
I believe the expect.assertions(2)
line is redundant here, and can safely be removed, because we already await
the async call to login()
.
Am I correct, or have I misunderstood how expect.assertions
works?