vbo*_*tio 5 babeljs babel-jest babel-loader
我正在为我的应用程序编写第一个测试,然后安装 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();
});
});
Run Code Online (Sandbox Code Playgroud)
运行测试时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.`
Run Code Online (Sandbox Code Playgroud)
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"],
]
}
}
},
Run Code Online (Sandbox Code Playgroud)
我的 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",
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?
归档时间: |
|
查看次数: |
935 次 |
最近记录: |