From f6b38b06a2bdc4cb3674796101dd209e5ed35eac Mon Sep 17 00:00:00 2001 From: Gasan Guseinov Date: Fri, 31 Jan 2025 15:40:12 +0100 Subject: [PATCH] update custom auth connector test Signed-off-by: Gasan Guseinov --- .../auth/oauth2/OAuth2CustomAuthConnector.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts index e5ef3cbc0d..cfed4d4714 100644 --- a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts +++ b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts @@ -23,6 +23,7 @@ import { OAuth2CreateOptionsWithAuthConnector, OAuth2Response, } from '../../../../index'; +import { waitFor } from '@testing-library/react'; const scopeTransform = (x: string[]) => x; @@ -54,7 +55,7 @@ class CustomAuthConnector implements AuthConnector { } describe('OAuth2CustomAuthConnector', () => { - it('should use provided auth provider', async () => { + it('should use custom auth connector', async () => { const popupMock = { closed: false }; jest.spyOn(window, 'open').mockReturnValue(popupMock as Window); @@ -88,11 +89,10 @@ describe('OAuth2CustomAuthConnector', () => { }; const oauth2 = OAuth2.create(options); - // so that AuthConnector calls openLoginPopup synchronously (not try to refresh the token) - const accessToken = oauth2.getAccessToken('myScope', { - instantPopup: true, - optional: false, - }); + const accessToken = oauth2.getAccessToken('myScope'); + + // wait until `openLoginPopup` has been called + await waitFor(() => expect(addEventListenerSpy).toHaveBeenCalled()); const listener = addEventListenerSpy.mock.calls[0][1] as EventListener;