Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.flat is not a function only with jest

When running my tests with jest, I had the above error;

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

Following the solution from that issue, https://github.com/kulshekhar/ts-jest/issues/828

I've installed core-js on dependencies and putting this in jest.config.js

setupFiles: ['core-js'],

I'd receive that another error;

Error: Uncaught [Error: Not supported]

And this is occurring only with jest, I'm using babel and webpack on my application and storybook without errors on flat.

My 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'
  }
}
like image 420
Guilherme Bayer Avatar asked Jul 20 '19 02:07

Guilherme Bayer


2 Answers

This error happens if your node version is old. Try to update it to the latest version.

like image 94
OlegKusov Avatar answered Sep 27 '22 17:09

OlegKusov


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

this problem can be solved by running

npm install --save-dev core-js

and adding core-js to your jest config's setupFiles

"setupFiles": ["core-js"]
like image 37
Ulad Kasach Avatar answered Sep 27 '22 16:09

Ulad Kasach