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

15 lines
548 B
JavaScript
Raw Normal View History

2020-11-30 16:57:02 +01:00
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({
2020-12-07 16:07:44 +01:00
json: () => new Promise((resolve) => resolve(responsesToUrls[url]) || { fetch: 'mock' }),
text: () => new Promise((resolve) => resolve(JSON.stringify(responsesToUrls[url])) || 'fetchmock'),
2020-11-30 16:57:02 +01:00
})
)
)
})