Unit Testing: Jest with NestJS
NestJS is a powerful backend framework which is inspired by Angular and works on TypeScript. NestJS comes with rich documentation and capabilities. It follows a modular approach thus our code is divided into different modules. If you have started using NestJS or are considering switching from another framework, you may be wondering how unit testing would be done. Let me take you through an example that shows how straightforward it can be to write unit test cases for our module.
Unit test cases in any application can detect bugs early, improve the quality of code, simplify the debugging process and reduce cost.
Let’s say we have the below files in a NestJS module named CatModule and I will demonstrate how to write unit test case for our file cats.controller.ts in CatModule.
cats.controller.ts
cats.service.ts
In the CatsController, we are using the CatsService function to fetch all cats. To start writing unit test cases, you should…