This chapter will describe how to test modules.
To use the testing features of the project, you need to make sure that the project contains the dependency: "@modern-js/plugin-testing"
, which can be done with modern new.
In Modern.js Module, the following conventions are in place for test cases, or files for writing tests:
tests
directory in the project directory is the directory for test cases and test files, no support for changing the directory for running test cases..test.[tj]sx?
are automatically recognized as test files by default.. [tj]sx?
suffixes are recognized as normal files that can be used as test utils
files or for other purposes.Once the dependencies are prepared and we know where to write the test cases, we can execute the tests with the following command:
After execution, you will see the results of the test:
Modern.js Module provides the following configurations for testing.
You can add it in modern.config.(j|t)s
.
For common modules, we can use the test function as follows:
@
points to the source directory, defined in tests/tsconfig.json
in the initialization project.modern test
.For components, Modern.js's Runtime API provides functionality for testing UI components, which is provided by @modern-js/runtime/testing
.
If you need to use the Runtime API, then you can turn it on via microgenerator.
@
points to the source directory, defined in tests/tsconfig.json
in the initialization project.modern test
.