目前尚未启用对实验语法“ jsx”的Jest测试支持

问题描述

我正在为我的应用程序编写第一个测试,然后安装Jest。

我的测试非常简单,所以我认为我收到的错误不是来自那里。

import React from 'react';
import renderer from 'react-test-renderer';
import FancyInput from './FancyInput';

describe('FancyInput',() => {
  it('should render correctly',() => {
    expect(
      renderer.create(
        <FancyInput />
      )
    ).toMatchSnapshot();
  });
});

运行测试时错误Support for the experimental Syntax 'jsx' isn't currently enabled

`Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.
    If you want to leave it as-is,add @babel/plugin-Syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.`

enter image description here

我的webpack文件包含以下内容

rules: [
  {
    test: /\.js$/,exclude: /node_modules/,use: {
      loader: 'babel-loader',options: {
        presets: [
          '@babel/preset-react',],plugins: [
          ["@babel/plugin-proposal-decorators",{ "legacy": true }],["@babel/plugin-proposal-optional-chaining"],["@babel/plugin-Syntax-jsx"],]
      }
    }
  },

我的package.json也有我认为必要的所有插件

"@babel/plugin-proposal-class-properties": "^7.10.4","@babel/plugin-proposal-decorators": "^7.4.4","@babel/plugin-proposal-optional-chaining": "^7.11.0","@babel/plugin-Syntax-jsx": "^7.10.4","@babel/preset-react": "^7.0.0",

在这里想念什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)