Codesandbox-client: Polyfill `fetch` in tests

Created on 7 May 2019  路  3Comments  路  Source: codesandbox/codesandbox-client

I believe that jest does this by default. It'd be great if codesandbox did it too.

Here's an example:

Edit 0qy6ov8x10

The test that fails:

test('fetch is defined on window', () => {
  expect(window.fetch).toBeDefined()
})

Most helpful comment

That was fast!

wow

All 3 comments

Note, my temporary fix is to add a src/setupTests.js file that does this:

import fetch from 'node-fetch'

if (!window.fetch) {
  window.fetch = fetch
}

Edit 0qy6ov8x10

Good one! This one was an easy fix luckily 馃槃. I'm expecting to deploy it tomorrow morning if that's okay.

For reference, it now works for me:
image

That was fast!

wow

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oliversturm picture oliversturm  路  3Comments

wojciechczerniak picture wojciechczerniak  路  3Comments

faceyspacey picture faceyspacey  路  3Comments

andreplaranja picture andreplaranja  路  3Comments

Haroenv picture Haroenv  路  3Comments