From 532e5f24ff183a26f004c3103218d0ad85426331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Cie=C5=9Blak?= Date: Fri, 7 Feb 2025 15:29:35 +0100 Subject: [PATCH] Make sure resp is handled before rejecting it --- web/packages/teleport/src/lib/useMfa.test.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/web/packages/teleport/src/lib/useMfa.test.tsx b/web/packages/teleport/src/lib/useMfa.test.tsx index ede9d0ac8f84c..38e8aafdfe139 100644 --- a/web/packages/teleport/src/lib/useMfa.test.tsx +++ b/web/packages/teleport/src/lib/useMfa.test.tsx @@ -235,14 +235,21 @@ describe('useMfa', () => { }) ); - let resp; + let resp: Promise; 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