jestjs - Jest 24.0.0 Plugin/Preset 文件不允许导出对象,只能导出函数

标签 jestjs babel-jest

从 Jest 23.6.0 升级到 24.0.0 后,我收到此错误:Plugin/Preset files are not allowed to export objects, only functions.
这是由这个提交引起的:https://github.com/facebook/jest/pull/7203/files
它记录了重大变化。

对于我们这些使用 require 的人,目前尚不清楚我们需要在我们的存储库中进行哪些更改来解决此问题。

Stack Overflow 上有许多类似的问题,但没有一个能引导我找到解决方案......

最佳答案

最近我在使用 Jest 24.0.0 时遇到了同样的问题。这就是我为让它运行所做的。

首先,我按照文档中的说明安装了依赖项,但我使用了 npm insted of yarn。

  npm install --save-dev babel-jest @babel/core @babel/preset-env

然后我不得不使用以下内容添加一个名为 babel.config.js 的文件:
// babel.config.js
module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current',
        },
      },
    ],
  ],
};

然后它开始正常工作。我希望这会有所帮助。

关于jestjs - Jest 24.0.0 Plugin/Preset 文件不允许导出对象,只能导出函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54379734/

相关文章:

node.js - typescript 和 Jest : Avoiding type errors on mocked functions

jestjs - Nuxt + Jest : unknow custom element if "components" is not set

javascript - 使用 Jest 响应 js 测试 bool 属性

reactjs - SecurityError : localStorage is not available for opaque origins with new testEnvironmentOptions. url 选项

reactjs - 如何使用 babel-jest 转译测试

node.js - 配置 Babel 和 Jest

vue.js - 使用 Vue 测试工具全局模拟数据

javascript - 在没有适当功能的情况下开 Jest 测试 Lambda? Node.js

javascript - 在 jest.mock(moduleName,factory) 工厂函数中模拟多个命名导出

reactjs - 类型错误 : Failed to load plugin 'jest' declared in '.eslintrc' : Class extends value undefined is not a constructor or null