我正在尝试为 react native 库设置 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 原生版本 : 0.61.5app.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 但无济于事。有人可以帮我吗?
最佳答案
在我更改 .babelrc
后它对我有用文件到 babel.config.js
.
关于javascript - SyntaxError - node_modules/react-native/Libraries/polyfills/error-guard.js : Missing semicolon. (14:4) 在 react 原生库中运行 jest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70080213/