Modern.js integrates the testing capabilities of Jest by default.
First need to execute pnpm run new
to enable "unit test/integration test" features:
After executing the above command, the "test": "modern test"
command will be added in package.json
automatically.
After registering the @modern-js/plugin-testing
plugin in modern.config.ts
, you can use the testing features:
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
.
Other testing APIs supported by Modern.js can be referred to here.
By default, Modern.js testing uses babel-jest for source code compilation. If you need to use ts-jest, you can configure it through testing.transform.