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


- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01