MCPcopy
hub / github.com/simstudioai/sim / createMockResponse

Function createMockResponse

packages/testing/src/mocks/fetch.mock.ts:39–63  ·  view source on GitHub ↗
(config: MockFetchResponse = {})

Source from the content-addressed store, hash-verified

37 * Creates a mock Response object.
38 */
39export function createMockResponse(config: MockFetchResponse = {}): Response {
40 const status = config.status ?? 200
41 const ok = config.ok ?? (status >= 200 && status < 300)
42
43 return {
44 status,
45 statusText: config.statusText ?? (ok ? 'OK' : 'Error'),
46 ok,
47 headers: new Headers(config.headers ?? {}),
48 json: vi.fn(async () => config.json ?? {}),
49 text: vi.fn(async () => config.text ?? JSON.stringify(config.json ?? {})),
50 body: config.body ?? null,
51 bodyUsed: false,
52 arrayBuffer: vi.fn(async () => new ArrayBuffer(0)),
53 blob: vi.fn(async () => new Blob()),
54 formData: vi.fn(async () => new FormData()),
55 clone: vi.fn(function (this: Response) {
56 return createMockResponse(config)
57 }),
58 redirected: false,
59 type: 'basic' as ResponseType,
60 url: '',
61 bytes: vi.fn(async () => new Uint8Array()),
62 } as Response
63}
64
65/**
66 * Creates a mock fetch that handles multiple URLs with different responses.

Callers 4

utils.test.tsFile · 0.90
createMockFetchFunction · 0.70
createMultiMockFetchFunction · 0.70
mockNextFetchResponseFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected