MCPcopy Index your code
hub / github.com/StarpTech/FastGraph / mockFetch

Function mockFetch

src/test-utils.ts:277–318  ·  view source on GitHub ↗
(
  json: any,
  headers: { [s: string]: any } = new globalThis.Headers(),
)

Source from the content-addressed store, hash-verified

275}
276
277export const mockFetch = (
278 json: any,
279 headers: { [s: string]: any } = new globalThis.Headers(),
280) => {
281 // @ts-ignore
282 const oldFetch = globalThis.fetch
283 let fetchInput: RequestInfo
284 let fetchInit: RequestInit | undefined
285
286 return {
287 mock() {
288 // @ts-ignore - faking it
289 globalThis.fetch = async (input: RequestInfo, init?: RequestInit) => {
290 fetchInput = input
291 fetchInit = init
292
293 return {
294 ok: true,
295 status: 200,
296 statusText: 'OK',
297 headers: new globalThis.Headers(Object.entries(headers)),
298 json() {
299 return json
300 },
301 }
302 }
303
304 return this
305 },
306 getArgs() {
307 return {
308 input: fetchInput,
309 init: fetchInit,
310 }
311 },
312 revert() {
313 globalThis.fetch = oldFetch
314 fetchInput = ''
315 fetchInit = undefined
316 },
317 }
318}
319
320export const getKVEntries = (m: Map<string, any>, json = true) => {
321 const obj: { [k: string]: any } = {}

Callers 2

apq.test.tsFile · 0.90
graphql.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected