{"id":10396,"library":"jest","title":"Jest","description":"Jest is a delightful JavaScript testing framework designed to ensure the correctness of any JavaScript codebase. As of version 30.3.0, it offers powerful features like snapshot testing, isolated environments, and a comprehensive assertion library. While major releases historically had longer intervals (v30 after three years), the project aims for more frequent major updates, alongside regular minor and patch releases.","status":"active","version":"30.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/jestjs/jest","tags":["javascript","ava","babel","coverage","easy","expect","facebook","immersive","instant","typescript"],"install":[{"cmd":"npm install jest","lang":"bash","label":"npm"},{"cmd":"yarn add jest","lang":"bash","label":"yarn"},{"cmd":"pnpm add jest","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"symbol":"defineConfig","correct":"import { defineConfig } from 'jest';"},{"symbol":"expect","correct":"import { expect } from '@jest/globals';"}],"quickstart":{"code":"// sum.ts\nexport function sum(a: number, b: number): number {\n  return a + b;\n}\n\n// sum.test.ts\nimport { sum } from './sum';\n\ndescribe('sum', () => {\n  it('adds 1 + 2 to equal 3', () => {\n    expect(sum(1, 2)).toBe(3);\n  });\n});\n\n// To run: `npx jest sum.test.ts`","lang":"typescript","description":"This example shows a simple TypeScript function and its corresponding test using Jest's `describe` and `it` blocks with `expect` assertions."},"warnings":[{"fix":"Consult the official migration guide for Jest 30.0.0 to update your configuration and tests.","message":"Jest v30.0.0 is a major release after three years, introducing a substantial number of changes that may require following the migration guide for existing projects.","severity":"breaking","affected_versions":">=30.0.0"},{"fix":"Upgrade your Node.js environment to a supported version (e.g., using `nvm install 20` and `nvm use 20`).","message":"Jest 30 requires Node.js v18.14.0, v20.0.0, v22.0.0, or >=v24.0.0. Older Node.js versions are no longer supported.","severity":"breaking","affected_versions":">=30.0.0"},{"fix":"If your project explicitly depended on `jest-runner`, review your setup to remove direct dependencies or migrate to alternative runner configurations if necessary.","message":"The `jest-runner` package was deprecated and removed starting from Jest 30.0.1.","severity":"breaking","affected_versions":">=30.0.1"},{"fix":"Ensure you are using Jest v30.1.3 or newer to properly mock Node.js built-in modules with `unstable_mockModule`.","message":"Previously, `unstable_mockModule` could have issues when attempting to mock `node:` prefixed core modules.","severity":"gotcha","affected_versions":"<30.1.3"}],"env_vars":null,"last_verified":"2026-04-18T00:00:00.000Z","next_check":"2026-07-17T00:00:00.000Z","problems":[{"fix":"Ensure your `package.json` has `\"type\": \"module\"` or configure Babel/TypeScript to transpile ES modules, and Jest to recognize your test files as modules.","cause":"Jest is attempting to run ES modules in a CommonJS context without proper configuration.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Ensure Jest is correctly installed and configured, and that you're running your tests via the `jest` command (e.g., `npx jest`) rather than executing test files directly.","cause":"Jest's global test functions (describe, it, expect) are not available in the current scope.","error":"ReferenceError: describe is not defined"},{"fix":"Verify your `jest.config.js` includes the correct `transform` configuration for your project's syntax, e.g., `'^.+\\.(ts|tsx)$': 'ts-jest'` or a Babel setup.","cause":"Jest's transformer (often Babel or ts-jest) is not correctly configured to process modern JavaScript syntax, TypeScript, or JSX/TSX.","error":"Jest encountered an unexpected token '<' (or similar)"},{"fix":"Install the required environment: `npm install --save-dev jest-environment-jsdom` or `yarn add --dev jest-environment-jsdom`.","cause":"Your Jest configuration specifies `testEnvironment: 'jsdom'` but the `jest-environment-jsdom` package is not installed.","error":"Error: Jest: a \"jest-environment-jsdom\" package is required"},{"fix":"Configure `moduleNameMapper` in your `jest.config.js` to map module paths, especially for aliases (e.g., `\"^@/(.*)$\": \"<rootDir>/src/$1\"`).","cause":"Jest's module resolver cannot find a specified module, often due to custom path aliases or non-standard module locations.","error":"Cannot find module './my-module' from 'my-test.js'"}],"ecosystem":"npm"}