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

Function createMultiMockFetch

packages/testing/src/mocks/fetch.mock.ts:77–99  ·  view source on GitHub ↗
(
  routes: Record<string, MockFetchResponse>,
  defaultResponse?: MockFetchResponse
)

Source from the content-addressed store, hash-verified

75 * ```
76 */
77export function createMultiMockFetch(
78 routes: Record<string, MockFetchResponse>,
79 defaultResponse?: MockFetchResponse
80) {
81 return vi.fn(async (url: string | URL | Request, _init?: RequestInit) => {
82 const urlString = url instanceof Request ? url.url : url.toString()
83
84 // Find matching route (exact or partial match)
85 const matchedRoute = Object.keys(routes).find(
86 (route) => urlString === route || urlString.includes(route)
87 )
88
89 if (matchedRoute) {
90 return createMockResponse(routes[matchedRoute])
91 }
92
93 if (defaultResponse) {
94 return createMockResponse(defaultResponse)
95 }
96
97 return createMockResponse({ status: 404, json: { error: 'Not Found' } })
98 })
99}
100
101/**
102 * Sets up global fetch mock.

Callers

nothing calls this directly

Calls 2

createMockResponseFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected