Skip to main content
Version: 14.3

Using with Babel

If you wish to use Babel, you need to say jest to transpile such files manually.

  1. Install dependencies required by the official Jest documentation for Babel integration.

  2. Install @babel/preset-env and add babel.config.js (or modify existing if needed) with the following content:

// babel.config.js
module.exports = function (api) {
api.cache(true);

const presets = ['@babel/preset-env'];
const plugins = [];

return {
presets,
plugins,
};
};

Note: do not use a .babelrc file otherwise the packages that you specify in the next step will not be picked up. CF Babel documentation and the comment You want to compile node_modules? babel.config.js is for you!.

  1. Update Jest configuration (by default TypeScript process untranspiled JS files which is source of the problem):
// jest.config.js
module.exports = {
//...
transform: {
'^.+\\.(ts|html)$': 'jest-preset-angular',
'^.+\\.js$': 'babel-jest',
},
};