首页 > 解决方案 > 使用 Jest 运行测试时无法忽略 node_module 中的包

问题描述

尽管配置了 Jest,但我在设置 jest 并运行测试时遇到了这个问题

    TypeError: Cannot read property 'Constants' of undefined

      at Object.<anonymous> (node_modules/@momo-platform/component-kits/components/qrcodeScanner/QRCodeScannerView.js:1:2882)
      at Object.<anonymous> (node_modules/@momo-platform/component-kits/index.js:1:22069)

  console.error node_modules/prop-types/factoryWithTypeCheckers.js:23
    Warning: Invalid arguments supplied to oneOf, expected an array, got 3 arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).

这是配置文件 jest.config.js:

module.exports = {
    preset: 'react-native',
    moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
    cacheDirectory: './cache',
    // "coveragePathIgnorePatterns": [
    //   "./app/utils/vendor"
    // ],
    coverageThreshold: {
        global: {
            statements: 80,
        },
    },
    moduleNameMapper: {
        '.+\\.(png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
    },
    transformIgnorePatterns: [
        'node_modules\/(?!(react-native|react-native-camera-kit|react-native-linear-gradient|react-native-iphone-x-helper|react-native-progress|@react-native-community|@momo-platform/component-kits/components/qrcodeScanner/QRCodeScannerView.js))(.*)',
    ],
};

大家可以帮我忽略 node_modules 中的 node_modules/@momo-platform/component-kits 问题吗?

标签: react-nativejestjs

解决方案


推荐阅读