I'm using https://github.com/github/fetch in my app, which works fine but I would like to test my code with Mocha and babel since I'm writing ES2016.
This does not work out of the box. I'm getting:
1) testApi.js Test api error handling:
ReferenceError: fetch is not defined
at callApi (callApi.js:10:10)
at Context.<anonymous> (testApi.js:8:40)
Because well, fetch is not defined. When I build for the browser fetch is exposed by webpack.
I've tried using https://github.com/bitinn/node-fetch but the api is slightly different and wants full url's instead of relative paths for example.
Is there a solution to this problem?
So, if anyone has this problem in the future:
import 'isomorphic-fetch'
in your index.js or otherwise root fileimport 'isomorphic-fetch'
in whatever test file calls fetch (or root test file if you have one)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With