.flat不仅具有笑话功能,

时间:2019-07-20 02:06:22

标签: jestjs babeljs babel-jest babel-polyfill core-js

以开玩笑的方式运行测试时,出现上述错误;

Error: Uncaught [TypeError: array.map(...).flat is not a function]

遵循该问题的解决方案,https://github.com/kulshekhar/ts-jest/issues/828

我已将core-js安装在依赖项上,并将其放入jest.config.js

setupFiles: ['core-js'],

我会收到另一个错误;

Error: Uncaught [Error: Not supported]

这只是开玩笑而已,我在应用程序和故事书上使用了babel和webpack,在flat上没有错误。

我的jest.config.js

const PATH = require('./path')

module.exports = {
  setupFilesAfterEnv: ['./rtl.setup.js'],
  moduleFileExtensions: ['js'],
  verbose: true,
  moduleNameMapper: {
    '@components(.*)$': `${PATH.source}/components/$1`
  },
  transform: {
    '^.+\\.js$': 'babel-jest'
  }
}

4 个答案:

答案 0 :(得分:2)

我安装了 ( 60% + ( 40% / 1.0 ) ) ---------------------------- ~ 1.2921 x ( 60% + ( 40% / 2.3 ) ) core-js),它对我有用。 还必须在测试文件导入的顶部添加@3.4.1

编辑:在未弹出的import 'core-js';项目中使用它,因此我无法访问create-react-app文件,也没有webpack的自定义配置(也{ {1}})。

答案 1 :(得分:1)

每个https://github.com/kulshekhar/ts-jest/issues/828#issuecomment-433976880

可以通过运行

解决此问题
npm install core-js

并将core-js添加到Jest配置的setupFiles

"setupFiles": ["core-js"]

答案 2 :(得分:1)

如果您的节点版本较旧,则会发生此错误。尝试将其更新到最新版本。

答案 3 :(得分:0)

搜索更多关于core-js的信息,因为它已替换为@ babel / polyfill,因此该配置对我有用。

[
  "@babel/preset-env",
  {
    "targets": {
      "node": 4
    },
    "useBuiltIns": "usage",
    "corejs": 3
  }
]

然后将core-js @ 3作为依赖项安装。