Skip to content

Commit

Permalink
Make sure resp is handled before rejecting it
Browse files Browse the repository at this point in the history
  • Loading branch information
ravicious authored and github-actions committed Feb 7, 2025
1 parent 0c7a7f3 commit 532e5f2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions web/packages/teleport/src/lib/useMfa.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,21 @@ describe('useMfa', () => {
})
);

let resp;
let resp: Promise<MfaChallengeResponse>;
await act(async () => {
resp = mfa.current.getChallengeResponse();
});

// Before calling mfa.current.cancelAttempt(), we need to write code that handles rejection of
// resp. Otherwise the test is going to fail because of unhandled promise rejection.
// eslint-disable-next-line jest/valid-expect
const expectedRespRejection = expect(resp).rejects.toEqual(
new MfaCanceledError()
);

await act(async () => mfa.current.cancelAttempt());

await expect(resp).rejects.toThrow(new MfaCanceledError());
await expectedRespRejection;
expect(mfa.current.attempt.status).toEqual('error');
expect(
mfa.current.attempt.status === 'error' && mfa.current.attempt.error
Expand Down

0 comments on commit 532e5f2

Please sign in to comment.