0

Jest documentation says:

You can also use the .resolves matcher in your expect statement, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail. If you expect a promise to be rejected, use the .rejects matcher. It works analogically to the .resolves matcher. If the promise is fulfilled, the test will automatically fail.

This is my code:

body = {
        currentPassword: "WrongPassword",
        newPassword: "UglyPassword",
};
expect(api(`users/${userId}/password`, { method: 'PATCH', json: body, headers: getAuthHeader(jwtData) })).rejects.toThrow();

body.currentPassword = "BadPassword";

The test fails because the password sent to the endpoint is "BadPassword". The documentation says that Jest WILL WAIT for promise which is not true. How can I make it wait? The test is not deterministic now.

Leos Literak
  • 8,805
  • 19
  • 81
  • 156

0 Answers0