To enable support for JSX syntax in React unit tests, you need to configure Babel to transpile JSX code. Here are the steps to follow:
\

  1. Install the required dependencies:\
    npm install --save-dev @babel/preset-react @babel/plugin-syntax-jsx\
    ```\
    


2. Create a Babel configuration file if you don't have one already. In the root directory of your project, create a file named .babelrc.

3. Inside the .babelrc file, add the following configuration:\

{\
  "presets": ["@babel/preset-react"],\
  "plugins": ["@babel/plugin-syntax-jsx"]\
}\
```\
\
4. Now, you can run your React unit tests without encountering the "experimental syntax 'jsx' isn't currently enabled" error.\
\
Note: If you're using a different method to configure Babel (e.g., `babel.config.js`), make the necessary changes in that file instead.
React 单测: 解决 'experimental syntax 'jsx' isn't currently enabled' 错误

原文地址: http://www.cveoy.top/t/topic/puBF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录