Unit testing in NestJS
Unit testing is a process of testing the smallest parts of a system that handle a certain business logic in the app and that can be isolated from the system itself.
It’s crucial to understand that having a clear separation of concern is key for better unit testing. A function that handles user creation, sends emails, and updates session management at the same time can give a developer a hard time when it comes to testing it, since it’s hard to isolate it from the system. That’s because it handles multiple logics at the same time.
We talked about the modular design of NestJS applications in prior chapters and we built our base REST API following it, so we can isolate our application blocks and test them.
In the philosophy of NestJS, all the business logic should be handled in the service files. In most cases, unit testing the service file is enough to cover the app’s unit testing.
Now that we know what unit testing is, let...