Jest: Error in [email protected]

Created on 10 Aug 2016  ยท  8Comments  ยท  Source: facebook/jest

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)

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.

All 8 comments

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.

  • react: "15.4.2",
  • react-native: "0.42.0"
  • babel-jest: "19.0.0,
  • babel-preset-react-native: "1.9.1"
  • jest: "19.0.2",
  • react-test-renderer: "15.4.2"

@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.

Was this page helpful?
0 / 5 - 0 ratings