14

TypeError: Cannot read property 'fetch' of undefined

  at node_modules/whatwg-fetch/fetch.js:4:8
  at Object.<anonymous> (node_modules/whatwg-fetch/fetch.js:466:3)
  at Object.<anonymous> (node_modules/jest-expo/src/setup.js:97:348)

Got error while running tests with jest-expo. If anyone have solution please share.

doelleri
  • 19,232
  • 5
  • 61
  • 65
Vyas Reddy
  • 1,226
  • 1
  • 13
  • 24

1 Answers1

1

Obviously this is a guess without a code snippet, but looking at what fetch.js looked like at the time, the undefined value whose fetch property we can't read is the variable self (see line 1), which was meant to be set to the this context (see line 466).

Therefore, it seems that fetch.js is expecting to run in an environment where this refers to the window, but jest-expo, being a testing tool, is running it in some other environment, probably in strict mode where this is undefined.