mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 21:06:04 +00:00
public commit
This commit is contained in:
18
app/__test__/core/helper.ts
Normal file
18
app/__test__/core/helper.ts
Normal file
@@ -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