mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
19 lines
493 B
TypeScript
19 lines
493 B
TypeScript
import { jest } from "bun:test";
|
|
|
|
let _oldFetch: typeof fetch;
|
|
export function mockFetch(responseMethods: Partial<Response>) {
|
|
_oldFetch = global.fetch;
|
|
// @ts-ignore
|
|
global.fetch = jest.fn(() => Promise.resolve(responseMethods));
|
|
}
|
|
|
|
export function mockFetch2(newFetch: (input: RequestInfo, init: RequestInit) => Promise<Response>) {
|
|
_oldFetch = global.fetch;
|
|
// @ts-ignore
|
|
global.fetch = jest.fn(newFetch);
|
|
}
|
|
|
|
export function unmockFetch() {
|
|
global.fetch = _oldFetch;
|
|
}
|