add mockHeaders test util

This commit is contained in:
Vyrtsev Mikhail
2019-07-06 13:58:58 -05:00
committed by Umputun
parent 81bf3ef35c
commit fedfe92781
2 changed files with 24 additions and 13 deletions
+3 -13
View File
@@ -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(() => {
+21
View File
@@ -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;
},
};