es-babel-jest

v1.0.0
esbuild + babel-jest default preprocessor for Jest
jest esbuild testing

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

npm i es-babel-jest

Metadata

  • MIT
  • >=10
  • Unknown
  • released 12/6/2021

Downloads

Maintainers