diff --git a/packages/browser/src/ClientAuthentication.spec.ts b/packages/browser/src/ClientAuthentication.spec.ts index 31a0851626..453931a17c 100644 --- a/packages/browser/src/ClientAuthentication.spec.ts +++ b/packages/browser/src/ClientAuthentication.spec.ts @@ -336,8 +336,12 @@ describe("ClientAuthentication", () => { // TODO: add tests for events & errors it("reverts back to un-authenticated fetch on logout", async () => { - // eslint-disable-next-line no-restricted-globals - history.replaceState = jest.fn(); + window.history.replaceState = jest.fn(); + window.addEventListener = jest + .fn() + .mockImplementation((_event: unknown, callback: unknown) => { + (callback as () => void)(); + }); const clientAuthn = getClientAuthentication(); const unauthFetch = clientAuthn.fetch; @@ -402,8 +406,12 @@ describe("ClientAuthentication", () => { mockEmitter.emit = jest.fn(); it("calls handle redirect", async () => { - // eslint-disable-next-line no-restricted-globals - history.replaceState = jest.fn(); + window.history.replaceState = jest.fn(); + window.addEventListener = jest + .fn() + .mockImplementation((_event: unknown, callback: unknown) => { + (callback as () => void)(); + }); const expectedResult = SessionCreatorCreateResponse; const clientAuthn = getClientAuthentication(); const unauthFetch = clientAuthn.fetch; @@ -456,8 +464,12 @@ describe("ClientAuthentication", () => { }); it("clears the current IRI from OAuth query parameters even if auth flow fails", async () => { - // eslint-disable-next-line no-restricted-globals - history.replaceState = jest.fn(); + window.history.replaceState = jest.fn(); + window.addEventListener = jest + .fn() + .mockImplementation((_event: unknown, callback: unknown) => { + (callback as () => void)(); + }); mockHandleIncomingRedirect.mockImplementationOnce(() => Promise.reject(new Error("Something went wrong")), @@ -468,8 +480,7 @@ describe("ClientAuthentication", () => { const url = "https://coolapp.com/redirect?state=someState&code=someAuthCode"; await clientAuthn.handleIncomingRedirect(url, mockEmitter); - // eslint-disable-next-line no-restricted-globals - expect(history.replaceState).toHaveBeenCalledWith( + expect(window.history.replaceState).toHaveBeenCalledWith( null, "", "https://coolapp.com/redirect", @@ -483,14 +494,17 @@ describe("ClientAuthentication", () => { }); it("clears the current IRI from OAuth query parameters in the implicit flow", async () => { - // eslint-disable-next-line no-restricted-globals - history.replaceState = jest.fn(); + window.history.replaceState = jest.fn(); + window.addEventListener = jest + .fn() + .mockImplementation((_event: unknown, callback: unknown) => { + (callback as () => void)(); + }); const clientAuthn = getClientAuthentication(); const url = "https://coolapp.com/redirect?state=someState&id_token=idToken&access_token=accessToken"; await clientAuthn.handleIncomingRedirect(url, mockEmitter); - // eslint-disable-next-line no-restricted-globals - expect(history.replaceState).toHaveBeenCalledWith( + expect(window.history.replaceState).toHaveBeenCalledWith( null, "", "https://coolapp.com/redirect", @@ -499,14 +513,17 @@ describe("ClientAuthentication", () => { }); it("preserves non-OAuth query strings", async () => { - // eslint-disable-next-line no-restricted-globals - history.replaceState = jest.fn(); + window.history.replaceState = jest.fn(); + window.addEventListener = jest + .fn() + .mockImplementation((_event: unknown, callback: unknown) => { + (callback as () => void)(); + }); const clientAuthn = getClientAuthentication(); const url = "https://coolapp.com/redirect?state=someState&code=someAuthCode&someQuery=someValue"; await clientAuthn.handleIncomingRedirect(url, mockEmitter); - // eslint-disable-next-line no-restricted-globals - expect(history.replaceState).toHaveBeenCalledWith( + expect(window.history.replaceState).toHaveBeenCalledWith( null, "", "https://coolapp.com/redirect?someQuery=someValue", diff --git a/packages/browser/src/Session.spec.ts b/packages/browser/src/Session.spec.ts index af03cb3452..f46d3da630 100644 --- a/packages/browser/src/Session.spec.ts +++ b/packages/browser/src/Session.spec.ts @@ -246,10 +246,9 @@ describe("Session", () => { it("uses current window location as default redirect URL", async () => { mockLocation("https://some.url"); const clientAuthentication = mockClientAuthentication(); - const incomingRedirectHandler = jest.spyOn( - clientAuthentication, - "handleIncomingRedirect", - ); + const incomingRedirectHandler = jest + .spyOn(clientAuthentication, "handleIncomingRedirect") + .mockResolvedValue(undefined); const mySession = new Session({ clientAuthentication }); await mySession.handleIncomingRedirect(); @@ -259,13 +258,12 @@ describe("Session", () => { ); }); - it("wraps up ClientAuthentication handleIncomingRedirect", async () => { + it("wraps ClientAuthentication handleIncomingRedirect", async () => { mockLocation("https://some.url"); const clientAuthentication = mockClientAuthentication(); - const incomingRedirectHandler = jest.spyOn( - clientAuthentication, - "handleIncomingRedirect", - ); + const incomingRedirectHandler = jest + .spyOn(clientAuthentication, "handleIncomingRedirect") + .mockResolvedValue(undefined); const mySession = new Session({ clientAuthentication }); await mySession.handleIncomingRedirect("https://some.url"); expect(incomingRedirectHandler).toHaveBeenCalled(); @@ -401,10 +399,9 @@ describe("Session", () => { it("preserves a binding to its Session instance", async () => { const clientAuthentication = mockClientAuthentication(); - const incomingRedirectHandler = jest.spyOn( - clientAuthentication, - "handleIncomingRedirect", - ); + const incomingRedirectHandler = jest + .spyOn(clientAuthentication, "handleIncomingRedirect") + .mockResolvedValue(undefined); const mySession = new Session({ clientAuthentication }); const objectWithHandleIncomingRedirect = { handleIncomingRedirect: mySession.handleIncomingRedirect,