用酶和笑话测试 React 给出错误无法从“index.js”中找到模块“@babel/polyfill/lib/noConflict”

阿沙·安巴利

我是单元测试的新手,我刚刚开始为我的 React 项目编写单元测试。我的项目是使用 create-react-app 创建的,我已经安装了所需的测试库,例如酶、酶适配器反应 16 和开玩笑酶。

我在 src 目录中创建了一个新文件 setupTests.js 并添加酶配置。

当我尝试使用命令运行单元测试时,npm test我收到以下错误,因此我的测试失败。

src/App.test.js
● Test suite failed to run

Cannot find module '@babel/polyfill/lib/noConflict' from 'index.js'

However, Jest was able to find:
    './ComponentName.jsx'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

下面是错误截图 在此处输入图片说明 在此处输入图片说明

Below is the setupTests.js file looks like inside the src directory

import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import 'jest-enzyme';

configure({ adapter: new Adapter() });

Below is my test App.test.js file looks like where I'm just trying to console.log and here it's failing. If I remove App's import it will work.

import React from 'react';
import App from './App'
import { shallow } from 'enzyme';

test("this is my first test", () => {
    console.log('this is my first test')
});

I'm trying this on WSL Ubuntu 18.04 LTS and Node 12.8.4

Can anyone please tell me where I'm making mistake and correct me and Kindly excuse if the question is repeated.

Thank you in advance.

Update

Here is the GitHub link where I tried to reproduce the error https://github.com/aashayamballi/react-jest-enzyme-testing-error

I'm assuming that inside components/TestComponent1.jsx I'm importing import { HotTable } from "@handsontable/react"; Because of this the test suite is failing and giving an error.

Aashay Amballi

As suggested by @tmhao2005 after installing @babel/polyfill tests started running without any errors.

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何解决 React 项目中的酶/Jest 错误“无法从 'react-router.js' 中找到模块 'react'”

用酶错误反应笑话测试

无法从“ ReactFiberTreeReflection.js”中找到模块“ react / lib / ReactCurrentOwner”

用Jest和酶测试React Router

Storyshots 玩笑 - 无法从“index.js”中找到模块“@storybook/react”

React Marquee 模块给出错误

Jest 测试错误 - 无法从“jest_expect.js”中找到模块“expect”

无法用笑话模拟模块,并测试函数调用

用酶和笑话测试 Formik 形式

VueJS 的故事书的 storyhot 配置和无法从“config-loader.js”中找到模块“@storybook/vue/dist/server/babel_config”的笑话错误

Jest失败React 16升级后无法从'ReactShallowRenderer.js'中找到模块'react / lib / React'

Jest 无法从测试文件中找到模块

用玩笑和酶在React中测试表单

用酶测试React Portal

无法从“node_modules/@testing-library/react/dist/pure.js”中找到模块“react-dom/client”

无法从“ setupTests.ts”中找到模块“酶”

用酶浅的react-router v4摩卡测试无法正常工作

无法从“/react/node_modules/react-redux/lib/components”中找到模块“react”

反应笑话和酶,找到带有隐藏属性的“选项”

错误:无法从调度程序中找到模块“ react / lib / Object.assign”

用酶测试`React.createRef` API

用酶测试react-intl组件

Maven无法从其他模块中找到测试超类

用玩笑和酶从事React功能成分法的研究;无法监视原始值

React.js-用酶模拟点击

React Native 错误:无法解析模块`./index`

为什么create-react-app别名无法从文件夹中找到index.js?

在模块内使用FormattedMessage时出错:错误:[React Intl]无法找到所需的`intl`对象

为什么Webpack无法从我的React Webapp中找到任何模块?