(
json: any,
headers: { [s: string]: any } = new globalThis.Headers(),
)
| 275 | } |
| 276 | |
| 277 | export 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 | |
| 320 | export const getKVEntries = (m: Map<string, any>, json = true) => { |
| 321 | const obj: { [k: string]: any } = {} |
no outgoing calls
no test coverage detected