MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / withMockedFetch

Function withMockedFetch

dashboard/test/shell-sdk.test.mjs:10–23  ·  view source on GitHub ↗
(mock, run)

Source from the content-addressed store, hash-verified

8const sdk = await importBundledModule(sdkPath);
9
10function withMockedFetch(mock, run) {
11 const hadFetch = Object.prototype.hasOwnProperty.call(globalThis, "fetch");
12 const originalFetch = globalThis.fetch;
13 globalThis.fetch = mock;
14 return Promise.resolve()
15 .then(run)
16 .finally(() => {
17 if (hadFetch) {
18 globalThis.fetch = originalFetch;
19 } else {
20 delete globalThis.fetch;
21 }
22 });
23}
24
25test("fetchJSON returns parsed body on success", async () => {
26 const seen = [];

Callers 1

shell-sdk.test.mjsFile · 0.85

Calls 2

resolveMethod · 0.80
callMethod · 0.45

Tested by

no test coverage detected