Ccb873611-c49d-44d4-ba5e-54c9124b7452

jest-30-migration-recipe

Migrates Jest tests to latest version (v30+) and updates related packages. Handles matcher aliases, config updates, and dependency upgrades.

Public
6 executions
0 stars
How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

Jest Latest Migration Codemod

A Codemod agent for migrating Jest tests to the latest version (v30+) and updating related packages. This agent handles:

  • ✅ Matcher alias migrations (e.g., toBeCalledtoHaveBeenCalled)
  • ✅ Jest package updates to latest versions
  • ✅ Jest configuration updates for compatibility
  • ✅ Code formatting after migration

Prerequisites

  • Node.js >= 18.0.0
  • npm or yarn
  • Codemod CLI installed globally: npm install -g codemod

Quick Start

Step 1: Run the Codemod

bash

Or run on a specific directory:

bash

Step 2: Install Dependencies

After running the codemod, install the updated packages:

bash

Or use your preferred package manager:

bash

Step 3: Update Test Snapshots

Run your tests and update snapshots:

bash

Or if your test command is different:

bash

What It Does

  1. Updates package.json: Updates all Jest-related packages to latest versions:

    • jest: ^30.0.0
    • @types/jest: ^30.0.0
    • babel-jest: ^30.0.0
    • ts-jest: ^30.0.0
    • jest-environment-jsdom: ^30.0.0
  2. Migrates Test Files: Replaces deprecated matcher aliases:

    • toBeCalledtoHaveBeenCalled
    • toBeCalledTimestoHaveBeenCalledTimes
    • toBeCalledWithtoHaveBeenCalledWith
    • lastCalledWithtoHaveBeenLastCalledWith
    • nthCalledWithtoHaveBeenNthCalledWith
    • toReturntoHaveReturned
    • toReturnTimestoHaveReturnedTimes
    • toReturnWithtoHaveReturnedWith
    • lastReturnedWithtoHaveLastReturnedWith
    • nthReturnedWithtoHaveNthReturnedWith
    • toThrowErrortoThrow
  3. Updates Jest Config: Ensures configuration is compatible with Jest 30+

  4. Formats Code: Runs Prettier (if available) to format migrated code

References

Ready to contribute?

Build your own codemod and share it with the community.