0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-22 08:40:03 +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({
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
})
)
)
})