Unit Testing
#
ConventionEvery unit test file should be placed next to the file it tests with the same name and the .spec.ts
extension. If this extension is not present then the file won't be executed when running the test commands.
Example:
#
Build and Run Unit Tests#
Watch mode (for development)This command builds and executes the unit tests. If you modify a file and save it, the code is rebuilt and the tests are run again. This is particularly useful in development: you do not need to re-run the command every time you make code changes.
The process runs forever until you stop it.
#
Simple mode (for CI and Git hooks)If you need to build and run the tests only once, you can use these two commands:
These commands are particularly useful when you want to integrate your tests into a CI pipeline or a Git hook.
#
Testing ControllersSee Controllers.
#
Testing ServicesSee Services & Dependency Injection.
#
Testing HooksSee Hooks.
#
Dependency Injection & Unit TestingFoalTS uses dependency injection to keep the code loosely coupled and so enhance testatibility.