Error in running test in [email protected]
it works in [email protected]
Using Jest CLI v14.1.0, jasmine2, babel-jest, jest-react-native preset
FAIL __tests__/Intro-test.js (0s)
โ Runtime Error
- ReferenceError: fetch is not defined
at Object.<anonymous> (node_modules/react-native/Libraries/Fetch/fetch.js:17:23)
1 test suite failed, 0 tests passed (0 total in 1 test suite, run time 8.169s)
Looks like we need to change this line, but I guess it needs to be done in a way to support React Native 0.30 and 0.31
https://github.com/facebook/jest/blob/master/packages/jest-react-native/src/index.js#L31
It's fine if we bump the peer-dep to 0.31. That way people with react-native 0.30 can use 14.1.2 and we'll publish 14.2.0 to work with 0.31.
I've opened a PR for react-native that should fix this in a backwards-compatible way. Otherwise jest could just import from whatwg-fetch directly.
(this was fixed in the latest update to jest-react-native).
Getting the same ReferenceError: fetch is not defined when running npm test on a fairly fresh project.
@buckhx Upgrading react-native, babel-jest, and jest to latest versions worked for us.
Having the same issue with
react-native-cli: 2.0.1
react-native: 0.48.1
jest: 21.0.1
The project is written in typescript. App works but jest tests fail due to missing fetch. When I import fetch from isomorphic-fetch tests work but app is not.
Most helpful comment
It's fine if we bump the peer-dep to 0.31. That way people with react-native 0.30 can use 14.1.2 and we'll publish 14.2.0 to work with 0.31.