Skip to content

Latest commit

 

History

History
72 lines (62 loc) · 1.21 KB

esm-support.md

File metadata and controls

72 lines (62 loc) · 1.21 KB
id title
esm-support
ESM Support

To use ts-jest with ESM support, you'll first need to check ESM Jest documentation.

ts-jest supports ESM via a config option useESM in combination with jest config option extensionsToTreatAsEsm.

There are also 3 presets to work with ESM.

Examples

Manual configuration

// jest.config.js
module.exports = {
  // [...]
  extensionsToTreatAsEsm: ['.ts'],
  globals: {
    'ts-jest': {
      useESM: true,
    },
  },
}
// OR package.json
{
  // [...]
  "jest": {
    "extensionsToTreatAsEsm": [".ts"],
    "globals": {
      "ts-jest": {
        "useESM": true
      }
    }
  }
}

Use ESM presets

// jest.config.js
module.exports = {
  // [...]
  preset: 'ts-jest/presets/default-esm', // or other ESM presets
  globals: {
    'ts-jest': {
      useESM: true,
    },
  },
}
// OR package.json
{
  // [...]
  "jest": {
    "preset": "ts-jest/presets/default-esm", // or other ESM presets,
    "globals": {
      "ts-jest": {
        "useESM": true
      }
    }
  }
}