gpt4 book ai didi

webpack - Jest 测试失败,错误代码为 "window is not defined"

转载 作者:行者123 更新时间:2023-12-03 07:22:39 26 4
gpt4 key购买 nike

我正在尝试开始学习最先进的网络开发ReactRedux .

现在我陷入了运行测试的困境。由于某种原因,Jest 失败了

Task :frontend:test
yarn jest v1.0.2
$ "/Users/gunnar/git/app.oakstair.se/frontend/node_modules/.bin/jest"
FAIL src/containers/App/App.test.js
● Test suite failed to run

ReferenceError: window is not defined

at Object.<anonymous> (config/polyfills.js:18:1)
at next (native)
at process._tickCallback (internal/process/next_tick.js:109:7)

我用谷歌搜索了一段时间没有成功......

This is my starting test.js

And this my App test code

最佳答案

我遇到了同样的问题,但我不认为修改全局变量是解决问题的方法。

问题是因为在我的 Jest 配置中,我将 testEnvironment 设置为 node,而它应该是 jsdom。对我来说,此设置位于 React starter 应用程序定义的文件 package.json 中。

关于webpack - Jest 测试失败,错误代码为 "window is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46274889/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com