【发布时间】:2019-10-12 06:52:05
【问题描述】:
似乎每个人和他们的母亲都遇到了这个问题。我从所有 SO 问题和 GH 票证中尝试的一切都没有奏效。
实际上应该很简单,因为我的项目几乎是一个新的准系统项目。但是我仍然无法弄清楚我的生活出了什么问题。
当我运行jest:
/Desktop/Dropbox/Programming/iphone-app/fe/App.spec.tsx:11
const tree = react_test_renderer_1.default.create(<App_1.default />).toJSON();
^
SyntaxError: Unexpected token <
我的配置文件:
// jest.config.js
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
-
// tsconfig.json
{
"compilerOptions": {
"allowJs": false,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react-native",
"lib": [
"es6"
],
"moduleResolution": "node",
"noEmit": true,
"strict": true,
"target": "esnext"
},
"exclude": [
"node_modules"
]
}
-
// babel.config.js
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
编辑#1
为了清楚起见,我尝试在 jest 配置文件中使用 react-native 预设,但没有成功(同样的错误):
// jest.config.js
module.exports = {
preset: 'react-native',
transform: {
'^.+\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
'^.+\\.tsx?$': 'ts-jest'
},
globals: {
'ts-jest': {
tsConfig: 'tsconfig.json'
}
},
testEnvironment: 'node',
};
【问题讨论】:
标签: reactjs typescript react-native jestjs babeljs