Skip to content

Commit 8fbc694

Browse files
committed
fix(mock-doc): provide mocked global fetch() fn
1 parent de0dc65 commit 8fbc694

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/mock-doc/window.ts

+14
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ export class MockWindow {
210210
return this.__elementCstr;
211211
}
212212

213+
fetch(input: any, init?: any): any {
214+
if (typeof fetch === 'function') {
215+
return fetch(input, init);
216+
}
217+
throw new Error(`fetch() not implemented`);
218+
}
219+
213220
focus(): any {
214221
/**/
215222
}
@@ -856,6 +863,13 @@ function resetWindow(win: MockWindow) {
856863
(win.document as any).defaultView = win;
857864
} catch (e) {}
858865
}
866+
867+
// ensure we don't hold onto nodeFetch values
868+
(win as any).fetch = null;
869+
(win as any).Headers = null;
870+
(win as any).Request = null;
871+
(win as any).Response = null;
872+
(win as any).FetchError = null;
859873
}
860874
}
861875

0 commit comments

Comments
 (0)