add mockHeaders test util
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user