Unit Testing: Jest with NestJS

KNNX Corp.
KNNX Corp.
Published in
5 min readAug 29, 2019

--

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…

--

--

KNNX Corp.
KNNX Corp.

KNNX is a global leader in Distributed Ledger Technology and Enterprise Products. To learn more, head over to: https://www.knnx.com/