Error : Cannot read property fetch. Using jest-expo with react native(错误:无法读取属性提取.使用 jest-expo 和 react native)
问题描述
TypeError:无法读取未定义的获取"属性
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)
使用 jest-expo 运行测试时出错.如果有人有解决方案,请分享.
Got error while running tests with jest-expo. If anyone have solution please share.
推荐答案
显然这是没有代码片段的猜测,但是看当时 fetch.js 的样子,undefined 值,其 fetch我们无法读取的 code> 属性是变量 self (参见第 1 行),它被设置为 this 上下文(参见第 466 行).
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).
因此,似乎 fetch.js 期望在 this 引用 window 的环境中运行,但 jest-expo,作为一个测试工具,正在其他一些环境中运行它,可能是在 this 是 undefined 的严格模式下.
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.
这篇关于错误:无法读取属性提取.使用 jest-expo 和 react native的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:错误:无法读取属性提取.使用 jest-expo 和 react native
基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
