mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-04 00:56:01 +00:00
public commit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user