diff --git a/src/utils/register.test.ts b/src/utils/register.test.ts index 66c84d9..a51ba7d 100644 --- a/src/utils/register.test.ts +++ b/src/utils/register.test.ts @@ -6,7 +6,11 @@ describe('utils/register', () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore window.navigator.serviceWorker = { - register: jest.fn(() => Promise.resolve()), + register: jest.fn(() => + Promise.resolve({ + unregister: jest.fn(), + }) + ), addEventListener: jest.fn(), removeEventListener: jest.fn(), }; diff --git a/src/worker/fetch.test.ts b/src/worker/fetch.test.ts index d68cead..0e827a0 100644 --- a/src/worker/fetch.test.ts +++ b/src/worker/fetch.test.ts @@ -14,7 +14,12 @@ describe('worker/fetch', () => { }); beforeEach(() => { - jest.spyOn(globalThis, 'fetch'); + Object.defineProperty(globalThis, 'fetch', { + configurable: true, + enumerable: true, + value: jest.fn(), + writable: true, + }); }); describe('refreshToken', () => { diff --git a/src/worker/interceptor.test.ts b/src/worker/interceptor.test.ts index 047261a..528687f 100644 --- a/src/worker/interceptor.test.ts +++ b/src/worker/interceptor.test.ts @@ -16,7 +16,12 @@ describe('worker/interceptor', () => { }); beforeEach(() => { - jest.spyOn(globalThis, 'fetch'); + Object.defineProperty(globalThis, 'fetch', { + configurable: true, + enumerable: true, + value: jest.fn(), + writable: true, + }); (getAuthState as jest.Mock).mockResolvedValue({ allowList: undefined, }); @@ -113,10 +118,12 @@ describe('worker/interceptor', () => { const location = response.headers.get('location'); - expect(location.startsWith('https://example.com/login?client_id=fooClientId&response_type=token&state=')) - .toBe(true); - expect(location.endsWith('&scope=&redirect_uri=https%3A%2F%2Fexample.com%2Ffoobar%2Fcallback%2Ffoo')) - .toBe(true); + // eslint-disable-next-line max-len + expect(location.startsWith('https://example.com/login?client_id=fooClientId&response_type=token&state=')).toBe( + true + ); + // eslint-disable-next-line max-len + expect(location.endsWith('&scope=&redirect_uri=https%3A%2F%2Fexample.com%2Ffoobar%2Fcallback%2Ffoo')).toBe(true); expect(response.status).toBe(302); }); @@ -157,6 +164,7 @@ describe('worker/interceptor', () => { 'foobartest123', 'foo', expect.stringMatching(/[a-z0-9]{16}/), + 'https://example.com', expect.stringMatching(/[a-z0-9]{128}/) ); }); diff --git a/src/worker/operations.test.ts b/src/worker/operations.test.ts index 0026006..3d90e8d 100644 --- a/src/worker/operations.test.ts +++ b/src/worker/operations.test.ts @@ -16,7 +16,12 @@ describe('worker/operations', () => { }); beforeEach(() => { - jest.spyOn(globalThis, 'fetch'); + Object.defineProperty(globalThis, 'fetch', { + configurable: true, + enumerable: true, + value: jest.fn(), + writable: true, + }); (jwtDecode as jest.Mock).mockImplementation((data) => data); }); @@ -26,8 +31,8 @@ describe('worker/operations', () => { (getAuthState as jest.Mock).mockReturnValue(state); - await expect(createSession('', 'mockProvider', '', 'http://example.com')) - .rejects.toThrow('No config found'); + // eslint-disable-next-line max-len + await expect(createSession('', 'mockProvider', '', 'http://example.com')).rejects.toThrow('No config found'); }); it('should fail if there is no valid providers', async () => { @@ -55,8 +60,8 @@ describe('worker/operations', () => { (getAuthState as jest.Mock).mockReturnValue(state); - await expect(createSession('', 'mockProvider', '123', 'http://example.com')) - .rejects.toThrow('Invalid state'); + // eslint-disable-next-line max-len + await expect(createSession('', 'mockProvider', '123', 'http://example.com')).rejects.toThrow('Invalid state'); }); it('should work for token flow', async () => {