Configures and runs Jest - Meta-built batteries-included JS/TS unit framework with built-in `expect`, snapshot testing, mocking (`jest.mock`, `jest.fn`, `jest.spyOn`, manual `__mocks__/`), test environment selection (`jsdom` / `node`), parallel workers, coverage via Istanbul, watch mode, and CI integration via `--ci` flag. Use when the user works with React (CRA / older Next.js) or Node services and needs the most ecosystem-supported JS test framework.
75
94%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Deep reference for jest-tests SKILL.md. Consult when wiring coverage
gating, CI runs (--ci), JUnit reporting, or the ESLint test-globals config.
jest --coverageOutput formats: text, lcov, html, json, json-summary. Configure via
coverageReporters in jest.config.js. The coverageThreshold field fails
the run if coverage drops below thresholds.
For the coverageThreshold per-file pattern:
coverageThreshold: {
'./src/critical-module/': {
branches: 95,
statements: 95,
},
'./src/legacy/': {
branches: 50,
},
},Per Jest CLI, --ci flag is critical for CI runs:
# .github/workflows/test.yml
- run: npm ci
- run: npx jest --ci --coverage --maxWorkers=2 --reporters=default --reporters=jest-junit
- uses: codecov/codecov-action@v4
with: { files: ./coverage/lcov.info }--ci semantics:
process.env.CI=true--maxWorkers=2 is typical for GitHub-hosted runners (2 CPUs); tune per
runner specs.
For JUnit XML output (consumable by junit-xml-analysis in qa-test-reporting):
npm install --save-dev jest-junit
JEST_JUNIT_OUTPUT_FILE=./test-results/junit.xml \
jest --ci --reporters=default --reporters=jest-junitPer jest-start:
// eslint.config.js
import {defineConfig} from 'eslint/config';
import globals from 'globals';
export default defineConfig([
{
files: ['**/*.test.js', '**/*.spec.js'],
languageOptions: {
globals: { ...globals.jest },
},
},
]);Or via eslint-plugin-jest:
npm install --save-dev eslint-plugin-jest{
"overrides": [{
"files": ["**/*.test.js", "**/*.spec.js"],
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"]
}]
}