Modern.js integrates the testing capabilities of Jest by default.

First need to execute pnpm run new enable [unit test/integration test] features:

? Please select the operation you want: Enable features ? Please select the feature name: Enable Unit Test / Integration Test

After executing the above command, the "test": "modern test" command will be automatically generated in package.json.

register plugin in modern.config.ts:

import testPlugin from '@modern-js/plugin-testing';

export default defineConfig({
  plugins: [..., testPlugin()],

Test file

Modern.js default recognized test file paths are: <rootDir>/src/**/*.test.[jt]s?(x) and <rootDir>/tests/**/*.test.[jt]s?(x).

If you need to customize the test directory, you can configure it with tools.jest.


Modern.js test support testing-library. API can be imported from @modern-js/runtime/testing.

import { render, screen } from '@modern-js/runtime/testing';

Other Modern.js supported testing APIs can be found here.


Modern.js tests use babel-jest for source code compilation by default. If you need to use ts-jest, you can configure it through testing.transform.