transformIgnorePatterns对于react-native预设的jest无法正常工作

ddrv8njm  于 2023-04-12  发布在  React
关注(0)|答案(1)|浏览(149)

得到此错误

/node_modules/@react-native/polyfills/error-guard.js:14
    type ErrorHandler = (error: mixed, isFatal: boolean) => void;
         ^^^^^^^^^^^^

    SyntaxError: Unexpected identifier

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (node_modules/react-native/jest/setup.js:469:6)

不过,我已经定了

transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-(native|universal|navigation)-(.*)|@react-native-community/(.*)|@react-navigation/(.*)|bs-platform|(@[a-zA-Z]+/)?(bs|reason|rescript)-(.*)+)"
    ]

transformIgnorePatterns": [
      "node_modules"
    ]

我已经把巴别塔设置好了

module.exports = function (api) {
  api.cache(true);

  const presets = ['@babel/preset-env', '@babel/preset-react'];
  const plugins = ['@babel/plugin-proposal-class-properties'];
  return {
    presets,
    plugins,
  };
};

我已经试过该高速缓存了
有人知道吗?

zkure5ic

zkure5ic1#

@react-native添加到Jest配置中。例如:

transformIgnorePatterns : [
      "node_modules/(?!(jest-)?@react-native|react-(native|universal|navigation)-(.*)|@react-native-community/(.*)|@react-navigation/(.*)|bs-platform|(@[a-zA-Z]+/)?(bs|reason|rescript)-(.*)+)"
    ]

相关问题