我有以下玩笑设置
package.json
"devDependencies": {
"@babel/cli": "7.0.0-beta.53",
"@babel/core": "7.0.0-beta.53",
"@babel/plugin-transform-flow-strip-types": "7.0.0-beta.53",
"babel-core": "^7.0.0-0",
"babel-jest": "23.4.0",
"enzyme": "3.3.0",
"enzyme-adapter-react-16": "1.1.1",
"enzyme-to-json": "3.3.4",
"flow-bin": "0.76.0",
"identity-obj-proxy": "3.0.0",
"jest": "23.4.1",
"jest-styled-components": "5.0.1",
}
jest.config.js
module.exports = {
testPathIgnorePatterns: ['.next/', 'node_modules/'],
setupFiles: ['<rootDir>/enzyme.config.js'],
moduleNameMapper: {
'\\.(css|less)$': 'identity-obj-proxy',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/file.js',
},
snapshotSerializers: ['enzyme-to-json/serializer'],
transform: {
'^.+\\.jsx?$': 'babel-jest',
},
};
enzyme.config.js
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() });
.babelrc(使用next.js v6)
{
"env": {
"test": {
"presets": [["next/babel", { "preset-env": { "modules": "commonjs" } }]],
"plugins": ["@babel/plugin-transform-flow-strip-types"]
},
"development": {
"presets": ["next/babel"],
"plugins": ["@babel/plugin-transform-flow-strip-types"]
},
"production": {
"presets": ["next/babel"],
"plugins": ["@babel/plugin-transform-flow-strip-types"]
}
}
}
当我运行事件最简单的测试时,我猜到了很多错误,这些错误可能与未解析响应有关,但是应该通过babel吗?当我在开发应用程序时,它可以在开发模式下工作。
我不断遇到的错误示例
SyntaxError: /__tests__/ImageAvatar.test.js:
意外令牌(12:30)
10 | describe('<ImageAvatar />', () => { 11 | it('Renders correctly', () => { > 12 | const component = shallow(<ImageAvatar src={src} alt={alt} />); /__tests__/Colour.test.js:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import
来自'../styleguide/lib/Colour'的颜色; ^^^^^^
SyntaxError: Unexpected identifier