【发布时间】:2022-01-01 21:44:54
【问题描述】:
我正在尝试为 react 本机库设置 jest,但出现以下错误
SyntaxError: react-native/Libraries/polyfills/error-guard.js: Missing semicolon. (14:4)
12 | let _inGuard = 0;
13 |
> 14 | type ErrorHandler = (error: mixed, isFatal: boolean) => void;
| ^
15 | type Fn<Args, Return> = (...Args) => Return;
react-native 版本:0.61.5
app.js
import { Dimensions } from 'react-native';
function sum(a, b) {
return a + b;
}
module.exports = sum;
app.test.js
const sum = require('./app');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
jest.config.js
module.exports ={
preset : 'react-native',
transformIgnorePatterns: [
'/node_modules/(?!(@react-native|react-native)/).*/'
]
}
.babelrc
{
"presets": ["react-native"]
}
我尝试了各种建议的解决方案,例如添加 transformIgnorePatterns,但无济于事。有人可以帮我吗?
【问题讨论】:
-
不确定这是否有帮助,但这看起来像一个 TypeScript 文件,但带有 .js 扩展名。
标签: javascript reactjs react-native unit-testing jestjs