【问题标题】:React-native jest test giving unexpected tokenReact-native 笑话测试给出了意外的令牌
【发布时间】:2019-04-30 15:32:08
【问题描述】:

从组件类中获取意外令牌。寻求有关如何进行的建议。

失败:

  ● 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 =

【问题讨论】:

  • 我也有同样的问题
  • 我在 react native 应用程序中运行 yarn test App-test.js 时也面临同样的问题。你有什么解决办法吗。 @克里斯

标签: react-native jestjs


【解决方案1】:

这对我有用https://github.com/expo/expo/issues/2595#issuecomment-440966998

我认为问题在于安装了 jest 和 jest-expo

【讨论】:

    【解决方案2】:

    对我来说,这很有效:

    "transformIgnorePatterns": [
        "/node_modules/(?!sentry|react-native).+\\.js$",
    ],
    

    请注意,您必须在此处列出所有 node_modules

    /Users/guillermo/alibrate/alibrate-mobile/node_modules/react-native/jest/mockComponent.js:20 static displayName = '组件';

    【讨论】:

    • 这对我不起作用我仍然收到此错误
    猜你喜欢
    • 1970-01-01
    • 2021-03-08
    • 2018-03-15
    • 2018-04-12
    • 2019-01-14
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多