Skip to content

ThomZz/es-babel-jest

 
 

Repository files navigation

es-babel-jest

Directly forked from https://github.com/ambar/es-jest (thanks!), es-babel-jest is a ESM/React/TypeScript preprocessor for Jest, powered by esbuild. It will transform any ES modules into valid CJS (CommonJS) modules, to make your tests written in ES modules works out of the box with jest. It also pipe babel-jest transforms once preprocessed with esbuild, to allow jest helpers "hoisting" and all babel-jest default behavior.

npm version

Install

npm install es-babel-jest --save-dev

Usage

Add preset to Jest config:

{
  "jest": {
    "preset": "es-babel-jest"
  }
}

// alternatively, specifying the files to transform:
{
  "jest": {
    "transform": {
      "\\.[jt]sx?$": "es-babel-jest"
    },
  }
}

Writes your test with ES modules:

import path from 'path'

test('parses extname', () => {
  expect(path.extname('foo.md')).toBe('.md')
})

Happy testing!

Related

About

ESM/React/TypeScript preprocessor for Jest, powered by esbuild + pipe default "babel-jest" preprocessor to the outputed CJS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 92.6%
  • TypeScript 7.4%