Skip to content

jest

npm version License: MIT Node.js Jest

> Jest configuration with ts-jest, coverage thresholds and sensible defaults.

> 🛠️ Maintenance mode: dependency and security updates only. New projects should use @jmlweb/vitest-config.

  • 🔧 TypeScript: ts-jest transform out of the box
  • 📊 Coverage: 80% global thresholds, text/json/html reporters
  • 🎯 Sensible defaults: Node environment, mocks cleared and restored between tests
  • 🚀 Configurable: createJestConfig() factory with typed options
Terminal window
npm install --save-dev @jmlweb/jest-config jest ts-jest @types/jest

> 💡 Upgrading? See the Migration Guide.

jest.config.mjs
import jestConfig from '@jmlweb/jest-config';
export default jestConfig;

With a TypeScript config file (jest.config.ts), Jest also needs ts-node.

jest.config.mjs
import { createJestConfig } from '@jmlweb/jest-config';
export default createJestConfig({
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
moduleNameMapper: { '^@/(.*)$': '<rootDir>/src/$1' },
});

jsdom needs jest-environment-jsdom installed.

import { createJestConfig } from '@jmlweb/jest-config';
export default createJestConfig({
coverageThreshold: {
global: { lines: 90, functions: 90, branches: 85, statements: 90 },
},
});
import jestConfig from '@jmlweb/jest-config';
export default {
...jestConfig,
testTimeout: 10000,
};

createJestConfig(options) options and defaults:

Option Default
testEnvironment 'node'
moduleFileExtensions ['ts', 'tsx', 'js', 'jsx', 'json']
testMatch ['**/*.{test,spec}.{ts,tsx,js,jsx}']
testPathIgnorePatterns /node_modules/, /dist/, /build/, /.git/, /.cache/
collectCoverageFrom ['src/**/*.{ts,tsx,js,jsx}']
coveragePathIgnorePatterns node_modules, dist, build, coverage, .d.ts, config, test and spec files
coverageThreshold global: 80 for lines, functions, branches, statements
coverageReporters ['text', 'json', 'html']
setupFilesAfterEnv [] (omitted when empty)
moduleNameMapper {} (omitted when empty)
transform ts-jest for .ts/.tsx with esModuleInterop and allowSyntheticDefaultImports
testTimeout 5000

Fixed settings: collectCoverage: false (use --coverage), verbose: true, clearMocks: true, restoreMocks: true, resetModules: false.

  • ✅ Existing Jest projects with TypeScript
  • ✅ Shared coverage baseline

Not for you if you are starting a new project: use @jmlweb/vitest-config.

Pass options to createJestConfig, or spread the result and override. Passing transform replaces the default entirely, so include the ts-jest entry again if you still need it.

{
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
}
}
  • Node.js >= 22.12.0
  • Jest >= 29.0.0
  • ts-jest >= 29.0.0
  • jest (>=29.0.0)
  • ts-jest (>=29.0.0)
  • @types/jest (>=29.0.0)

Breaking: Node.js >= 22.12.0 is required.

  1. Upgrade Node.js to 22.12.0 or later.
  2. Update: npm install --save-dev @jmlweb/jest-config@latest

See the Changelog for details.

MIT