0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 18:26:15 +01:00
posthog/jest.setup.fetch-mock.js
2020-12-07 16:07:44 +01:00

15 lines
548 B
JavaScript

jest.mock('node-fetch', () => {
const responsesToUrls = {
'https://google.com/results.json?query=fetched': { count: 2, query: 'bla', results: [true, true] },
}
return jest.fn(
(url) =>
new Promise((resolve) =>
resolve({
json: () => new Promise((resolve) => resolve(responsesToUrls[url]) || { fetch: 'mock' }),
text: () => new Promise((resolve) => resolve(JSON.stringify(responsesToUrls[url])) || 'fetchmock'),
})
)
)
})