我正在尝试在反应中进行开玩笑/酶的测试
我有这个测试:
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme'
import WorkOutForm from './workOutForm';
describe('WorkOutForm', () => {
it('should start a new workoutForm with empty state', () => {
const component = mount(<WorkOutForm/>)
expect(component).toMatchSnapshot();
});
})
但是当我做npm run test
时我会收到:
src / workout / workOut.test.js●测试套件无法运行
babel-jest: Babel ignores src/workout/workOutForm.jsx - make sure to include the file in Jest's transformIgnorePatterns as well.
我尝试将此文件添加到package.json中:
"jest": {
"transformIgnorePatterns": [
"src/workout/workOutForm.jsx"
]
}
但是我收到相同的错误。 我必须把它放在哪里?
答案 0 :(得分:0)
我必须把它放在哪里?
您应该不忽略jsx源文件。您需要做的是使用babel将jsx转换为js。
您需要使用babel-preset-react。这将自动添加@babel/plugin-transform-react-jsx
进行转换。
然后将其放入您的.babelrc
{
"presets": ["@babel/preset-react"]
}
答案 1 :(得分:0)
我已经遇到此错误,并且我修改了以下代码:
"ignore": [
"./test",
"./src/assets",
"./src/stories",
"./src/.storybook"
]
对此:
"ignore": [
"./src/assets",
"./src/stories",
"./src/.storybook"
]
我从.babelrc忽略道具中删除了测试文件夹,它对我有用!