微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

React 测试未运行 - 运行时自动时无法设置 pragma 和 pragmaFrag

如何解决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 行不会改变任何内容

任何帮助将不胜感激。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。