Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : Cannot read property fetch. Using jest-expo with react native

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.

like image 231
Vyas Reddy Avatar asked Nov 04 '17 14:11

Vyas Reddy


1 Answers

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.

like image 64
Jack Robinson Avatar answered Nov 15 '22 01:11

Jack Robinson