Migrating from Jest
Rstest provides Jest-compatible test, assertion, and mock APIs. Follow this guide to migrate a Jest project to Rstest:
Using Agent Skills
If you are using a Coding Agent that supports Skills, install the migrate-to-rstest skill to assist with migrating from Jest to Rstest:
Installation and setup
Install @rstest/core as a development dependency:
Update the test script in package.json to run rstest instead of jest:
CLI option mappings
Some Jest CLI flags map directly to Rstest, while others move into config. Use this table for the common option differences you are likely to hit during migration:
Configuration migration
Update your Jest config file (e.g., jest.config.js or jest.config.ts) to a rstest.config.ts file:
Jest configuration mappings
When migrating, walk through every field in your jest.config.js and match it against the table below — map it, restructure it, or drop it. Fields not listed here may not map 1:1; verify against the Rstest config reference before dropping them silently.
For more details, please refer to the Configuration section.
Inject globals
Rstest does not mount the test APIs (e.g., describe, expect, it, test) to the global object by default, which is different from Jest.
If you want to continue using the global test APIs, you can enable the globals option in your rstest.config.ts file:
To enable TypeScript to properly recognize the global APIs, add the @rstest/core/globals type declaration in your tsconfig.json:
File-level environment comments
If your Jest tests use file-level environment comments, Rstest recognizes Jest environment comments during migration:
You can keep these comments as-is or rename them to @rstest-environment / @rstest-environment-options. The options value must be a single-line JSON object. Supported environments are node, jsdom, and happy-dom.
Dependency export conditions
By default, Rstest enables the development export condition when bundling dependencies, while Jest does not. After migrating, a dependency may therefore load a different entry from its package.json exports, even though both runners default NODE_ENV to 'test'.
For example, Emotion disables its speedy style insertion in development builds to support style debugging and source maps. This creates more <style> elements and can slow down style-heavy jsdom tests.
If this difference causes a regression in your jsdom tests, use resolve.byDependency through tools.rspack to omit development for ESM and CommonJS dependencies:
The browser condition is needed for DOM environments such as jsdom and happy-dom. For the same issue in the node environment, use testEnvironment: 'node' and remove browser from both lists.
These lists preserve the distinction between import and require and leave other dependency types, such as CSS imports, unchanged. Do not add '...': it would restore the default conditions, including development. If your project uses custom export conditions, add them to the corresponding lists.
This configuration addresses the development export difference; it does not reproduce all of Jest's resolution behavior. It keeps Rspack's module and webpack conditions, does not enable the production condition, and leaves NODE_ENV unchanged. Dependencies may lose checks or warnings provided only by their development exports, so apply it when needed rather than to every migrated project.
Code transformation
Unlike Jest's babel-jest, Rstest transforms code with SWC by default. Most projects need no extra transform config; customize SWC options through tools.swc when needed.
Jest itself gets module resolution and transformation from moduleNameMapper and transform, rather than from tsconfig.json. If you use ts-jest, do not assume that its TypeScript transform settings carry over: Rstest automatically applies compilerOptions.paths for resolution, while transformation settings, such as decorator syntax or output-target requirements, should be reviewed and configured through Rstest when needed. An adapter can inherit or infer additional settings, so refer to the documentation for the adapter you use. See source.tsconfigPath.
Rstest transforms files that are part of its bundle graph. If your project previously relied on ts-jest runtime transforms, see Code outside the bundle graph uses native Node.js behavior.
If you use custom Babel plugins or presets, add Rsbuild's Babel plugin:
Environment variables
Rstest mirrors Jest's two main injected variables under different names:
Replace any references in tests, fixtures, or setupFiles:
See Environment variables for the full list.
Update test API
Test API
Update your test API imports from @jest/globals to @rstest/core:
Replace jest.<api> calls with rs.<api> (or its longer alias rstest). See Rstest APIs for the full list.
Manual mocks for npm packages
Jest automatically uses a manual mock such as __mocks__/zustand.ts in the project root when a test imports zustand. To use the same file in Rstest, call rs.mock('zustand') in the test file. To apply the mock to every test file, register it once in a file listed in setupFiles.
Loading actual modules (requireActual)
In Jest, jest.requireActual() synchronously loads the unmocked implementation in factories and tests; in Rstest, hoisted rs.mock() factories must be synchronous, so use a static import with with { rstest: 'importActual' } (use rs.importActual in async tests, rs.requireActual for CommonJS modules, and see Mocking):
Virtual module mocks
When migrating a Jest virtual mock, declare the module and configure resolve.alias (see Mocking), then remove Jest's third argument:
Done callback
The done callback is not supported in Rstest. Instead, you can return a Promise or use async/await for asynchronous tests.
If you need to handle errors, you can modify it as follows:
Hooks
Rstest runs afterEach and afterAll hooks in reverse declaration order by default. Set sequence.hooks: 'list' to run hooks within each suite in declaration order, matching Jest. This matters when one library's cleanup must run before another, such as unmounting components before resetting stores.
When beforeEach or beforeAll returns a function, Rstest registers it as a cleanup callback to run after the test or suite. Unlike Jest, which ignores hook return values, an arrow function with an implicit return such as beforeEach(() => doSomething()) runs the returned value during teardown if doSomething() returns a function. Wrap the body in braces so nothing is returned:
Snapshot format
Rstest snapshots use a different key format than Jest. Existing Jest snapshot files will not match Rstest's generated keys on the first run — the snapshot bodies are unchanged, only the key formatting differs.
Key separator change
Jest separates the suite name and test name with a space and appends the snapshot label after : . Rstest joins all three with >:
For the example above, the parts are:
overlay— suite name (describe(...)).should not show a warning when "client.overlay.warnings" is "false"— test name (it(...)/test(...)).page html— snapshot label from.toMatchSnapshot('page html').1— snapshot index for that label in the test.
Updating snapshots
rstest -u re-records snapshots in Rstest's key format:
Reviewing the diff
Separator-only key renames and key-order changes with no body diff are formatting-only; only body changes under the same key indicate real behavior changes.
ESM and CJS
Rstest supports ESM natively (no NODE_OPTIONS=--experimental-vm-modules needed) as well as CommonJS projects.
ESM vs CJS mocking
In Rstest, rs.mock() targets the import entry, whereas modules loaded through require() with a separate CommonJS entry need rs.mockRequire() (see Mock CommonJS modules):