小编jam*_*ani的帖子

测试react.js时出现“ReferenceError:waitForElement未定义”

我正在使用 Jest 和 react-testing-library 测试调用异步函数的组件。当我运行测试时出现错误ReferenceError: waitForElement is not defined

按照这个说明我尝试过:

  1. withoutuseBuiltins在 中的选项.babelrc,包括@babel/polyfill在文件顶部的app.test.jsx,以及@babel/polyfill在 中的条目数组中没有的选项webpack.config.jsReferenceError: waitForElement is not defined我从测试运行中收到错误,但应用程序编译成功

  2. with useBuiltIns: 'entry',包括@babel/polyfill在文件顶部app.test.jsx,而 without 则@babel/polyfill位于 中的条目数组中webpack.config.js。我得到了Cannot find module 'core-js/modules/es6.array.every' from 'app.test.jsx',应用程序无法编译。

  3. with useBuiltIns: 'entry',不包括@babel/polyfill在文件顶部app.test.jsx,并且WITH@babel/polyfill位于 中的条目数组中webpack.config.jsReferenceError: waitForElement is not defined我从测试运行中 收到错误,并且应用程序无法编译。

这是案例 1 中的代码:

在 …

reactjs jestjs babeljs react-testing-library

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

babeljs ×1

jestjs ×1

react-testing-library ×1

reactjs ×1