reactjs - React 测试未运行 - 运行时自动时无法设置 pragma 和 pragmaFrag
问题描述
直到最近,我的测试都运行良好,除了顶级App
组件冒烟测试外,它们都仍然可以正常运行并通过。
测试代码:
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { render, waitFor } from '@testing-library/react';
import { ToastProvider } from 'react-toast-notifications'
import App from './App';
it('renders without crashing', async () => {
const { getByText } = render(
<MemoryRouter>
<ToastProvider>
<App />
</ToastProvider>
</MemoryRouter>
);
await waitFor(() => {
expect(getByText("You'll need to sign in to use this feature.")).toBeInTheDocument();
});
});
错误:
Test suite failed to run
SyntaxError: /Users/druserkes/Desktop/zephyrx/zephyrx-dr-dashboard/node_modules/react-toast-notifications/dist/ToastContainer.js: pragma and pragmaFrag cannot be set when runtime is automatic.
> 1 | 'use strict';
| ^
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
at File.buildCodeFrameError (node_modules/react-scripts/node_modules/@babel/core/lib/transformation/file/file.js:250:12)
at NodePath.buildCodeFrameError (node_modules/@babel/traverse/lib/path/index.js:138:21)
at PluginPass.enter (node_modules/babel-preset-react-app/node_modules/@babel/plugin-transform-react-jsx/lib/create-plugin.js:163:28)
at newFn (node_modules/@babel/traverse/lib/visitors.js:175:21)
at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:55:20)
at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:42:17)
at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:92:31)
at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:116:16)
at TraversalContext.visitSingle (node_modules/@babel/traverse/lib/context.js:85:19)
at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:144:19)
注释掉'use strict'
文件中的行node_modules
不会改变任何东西。
任何帮助将不胜感激。
解决方案
推荐阅读
- amazon-web-services - Ansible:未找到自动缩放组的新创建/旧启动配置
- android - 由于一个应用程序向其他应用程序发送的广播超时而导致 ANR
- python - 用双引号正确读取 pandas 中的 CSV 文件
- python - 从另一个数据帧动态生成数据帧
- tomcat8 - 如何从 URL 中隐藏端口号 8443 - tomcat 8.5
- python - vtk 阅读器不会从二进制 .vtk 文件中读取所有数据数组
- ansible - 可以使用 Consul KV 商店获取库存详细信息吗?
- python - “python a/b.py”和“python -m ab”之间的区别
- facebook - Facebook javascript sdk 分享视频未按预期工作
- node.js - 错误:ModuleNotFoundError:没有名为“email.FeedParser”的模块