React native React本机jest测试给出意外令牌
正在从组件类获取意外标记。寻求关于如何继续的建议 失败:React native React本机jest测试给出意外令牌,react-native,jestjs,React Native,Jestjs,正在从组件类获取意外标记。寻求关于如何继续的建议 失败: ● Test suite failed to run C:/../react-native/jest/mockComponent.js: Unexpected token (20:23) Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e
● Test suite failed to run
C:/../react-native/jest/mockComponent.js: Unexpected token (20:23)
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
18 |
19 | const Component = class extends SuperClass {
> 20 | static displayName = 'Component';
| ^
21 |
22 | render() {
23 | const name =
这对我有用
我认为问题在于为我安装了jest和jest expo,这很有效:
"transformIgnorePatterns": [
"/node_modules/(?!sentry|react-native).+\\.js$",
],
请注意,您必须在此处列出所有节点模块
/Users/guillermo/alibrate/alibrate mobile/node_modules/react native/jest/mockComponent.js:20
静态显示名称='组件' 我也有同样的问题,在react native应用程序中运行纱线测试App-test.js时,我也面临同样的问题。你有什么解决办法吗@Christis对我不起作用我还是会犯这个错误