diff --git a/frontend/app/common/fetcher.test.ts b/frontend/app/common/fetcher.test.ts index 8d1e54f2..d45be047 100644 --- a/frontend/app/common/fetcher.test.ts +++ b/frontend/app/common/fetcher.test.ts @@ -1,23 +1,13 @@ import fetcher from './fetcher'; +import { mockHeaders } from '@app/testUtils/mockHeaders'; describe('fetcher', () => { - let originalHeaders = (window as any).Headers; - beforeAll(() => { - originalHeaders = (window as any).Headers; - (window as any).Headers = class { - append() {} - has() { - return false; - } - get() { - return null; - } - }; + mockHeaders.mock(); }); afterAll(() => { - (window as any).Headers = originalHeaders; + mockHeaders.restore(); }); afterEach(() => { diff --git a/frontend/app/testUtils/mockHeaders.ts b/frontend/app/testUtils/mockHeaders.ts new file mode 100644 index 00000000..6c335f1b --- /dev/null +++ b/frontend/app/testUtils/mockHeaders.ts @@ -0,0 +1,21 @@ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const originalHeaders = (window as any).Headers; + +export const mockHeaders = { + mock: () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (window as any).Headers = class { + append() {} + has() { + return false; + } + get() { + return null; + } + }; + }, + restore: () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (window as any).Headers = originalHeaders; + }, +};