首先,我只想说在我提出这个问题之前我搜索并尝试了很多,我看到很多类似的主题,但是任何人都给了我一个答案 .
我正在使用react,redux,redux-form,webpack,css-modules .
并尝试使用jest测试我的项目,我收到此错误:
C:\ PROJECT \ node_modules \ redux-form \ es \ getFormValues.js:1从'./selectors/getFormValues'导入createGetFormValues; ^^^^^^ SyntaxError:意外的令牌导入
我认为在测试之前,redux-form不会被编译为es5 .
我的 test.test.js 看起来像:
import React from 'react';
import {configure,render} from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';
import TestComponent from '../../../components/TestComponent ';
describe('TestComponent ', () => {
configure({adapter: new Adapter()});
it('snapshot', () => {
expect(render(<TestComponent/>)).toMatchSnapshot();
});
});
我的 .babaelrc 配置文件如下所示:
{
"presets": [
"es2015",
"react"
],
"plugins": [
"transform-class-properties",
"transform-decorators",
"transform-object-rest-spread"
]
}
我的 package.json
jest配置如下:
"jest": {
"collectCoverageFrom": [
"PROJECT/**/*.{js}"
],
"moduleNameMapper": {
"\\.(css|scss)$": "identity-obj-proxy"
}
}
我应该如何正确配置,开玩笑,没有任何错误?
1 回答
我需要更改我的组件的导入:
至