`尝试检测主机组件名称触发了以下错误:
意外的代币“导出”
您的配置似乎存在问题,导致 React Native 测试库无法正常工作。 请检查您是否使用兼容版本的 React Native 和 React Native 测试库。
25 | const store = setupStore();
26 |
> 27 | const { getByText } = render(
| ^
28 | <Provider store={store}>
29 | <UserDisplay />
30 | </Provider>`
我正在使用 React Native 测试库和笑话来测试示例组件。
#tsconfig
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"jsx": "react",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src", "__tests__"]
}
module.exports = {
presets: [
'module:@react-native/babel-preset',
'@babel/preset-env',
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: [
['@babel/plugin-transform-class-properties', { loose: true }],
['@babel/plugin-transform-private-methods', { loose: true }],
['@babel/plugin-transform-private-property-in-object', { loose: true }],
],
};
import type { Config } from '@jest/types';
const config: Config.InitialOptions = {
preset: 'react-native',
transform: {
'^.+\\.[tj]sx?$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
transformIgnorePatterns: [
'node_modules/(?!(react-native|@react-native|@react-navigation|react-redux)/)',
],
>! moduleNameMapper: {
>! '\\.svg': '<rootDir>/__mocks__/svgMock.js',
>! '\\.(jpg|jpeg|png|gif|webp|svg)$': '
>! <rootDir>/__mocks__/fileMock.js',
},
};
export default config;
['@babel/preset-env', { targets: { node: 'current' } }]
** 从 babel.config 中删除此行后问题得到解决**