How to use the Jest config generator
- Choose the Test environment: Node or jsdom (browser-like).
- Keep TypeScript via ts-jest ticked for
.tstests, or untick it for plain JavaScript. - Tick Collect coverage and set Coverage threshold %; 0 means no minimum.
- Optionally fill in Test roots (comma-separated folders) and a Setup file after environment, such as
jest.setup.ts. - Tick Stub CSS imports if components import style files, pick the Module format, then copy the config and run the install command.
What it does and when to use it
Jest runs without any config, but real projects soon need one: TypeScript compilation, a browser-like DOM, a setup file for test helpers, or a coverage gate in CI. This tool writes those settings in one go and lists the packages they depend on, which is where hand-written configs usually go wrong.
If you skip ts-jest, the Babel config generator gives Jest a way to read modern syntax and TypeScript. The tsconfig generator sets up the compiler options ts-jest reads, and the GitHub Actions generator can run npm test on every push so the coverage threshold actually blocks bad merges.
How it works
The file opens with a type comment so editors offer autocomplete, then adds only what you chose:
preset: 'ts-jest'and the TypeScript packages when ts-jest is on;testEnvironment, plusjest-environment-jsdomfor jsdom;rootsandsetupFilesAfterEnv, with<rootDir>/added in front of each path;- a
moduleNameMapperthat sends.css,.less,.scssand.sassimports toidentity-obj-proxy; - coverage with the V8 provider, gathered from
src/**, and a global threshold for branches, functions, lines and statements.
clearMocks: true resets mock calls between tests. Option names match the Jest configuration docs; the tool targets Jest 30.
Worked examples
Defaults: Node, ts-jest, 80% coverage, roots src.
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts'],
followed by global: { branches: 80, functions: 80, lines: 80, statements: 80 },. Install: npm install --save-dev jest ts-jest @types/jest typescript.
A JavaScript component library. jsdom, no ts-jest, no coverage, CSS stubs on, ES module, setup file ./jest.setup.js, roots cleared. The config gains setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], and ends with export default config;. Install: npm install --save-dev jest jest-environment-jsdom identity-obj-proxy.
Limits and tips
- Coverage is always collected from
src/. EditcollectCoverageFromif your code lives elsewhere. - Path aliases such as
@/need their ownmoduleNameMapperentry. - The setup file is only referenced. Create it yourself, for example to import
@testing-library/jest-dom.
Frequently asked questions
When should I choose jsdom instead of Node?
Why is jest-environment-jsdom a separate install?
What happens when coverage falls below the threshold?
My project uses "type" set to "module". Which format do I pick?
Do I need ts-jest for TypeScript tests?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.