React-GA + Redux v7 与 jest 的不兼容问题

React-GA + Redux v7 incompatibility issue with jest

我正在使用 react-ga v2.5.7,为此我更新了 react-redux v7.0.2,并且我正在使用 jest v24.7.1

我在testMode中设置了react-ga,在我的jest.setup.js中被mock了。但是每次我 运行 我的测试总是遇到同样的问题,大多数测试都因为一些奇怪的原因而失败:

Test suite failed to run

    Cannot find module '@icons/material/CheckIcon' from 'SwatchesColor.js'

    However, Jest was able to find:
        './SwatchesColor.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

    However, Jest was able to find:
        './SwatchesGroup.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

    However, Jest was able to find:
        'components/swatches/Swatches.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

    However, Jest was able to find:
        './VisualIdentityColorPicker.js'
        './VisualIdentityColorPicker.spec.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

    However, Jest was able to find:
        './VisualIdentityBackgroundSelector.js'
        './VisualIdentityBackgroundSelector.spec.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

尽管 SwatchesColors 是一个完全不相关的模块的依赖项。 在我看来,存在不兼容问题,我的项目中唯一发生变化的是 react-ga 的添加和 react-redux 的更新,因为有人遇到过类似的问题吗? 你是怎么解决的?

我发现了实际问题,它似乎与未导入的组件有关,该组件在测试中导致了奇怪的行为。

导入后,问题就消失了。