NestJS Unit Testing - Test Controller (with Guards) and Service

preview_player
Показать описание
In this video we use Jest to create unit tests for our feed controller and service. The feed controller has guards and other dependencies are mocked. We also unit test our service, which has an observable. After watching this video you will understand how to do unit tests with Jest, particularly within a NestJS environment.

--------------------------------------------------
Recommended Udemy courses
--------------------------------------------------

Рекомендации по теме
Комментарии
Автор

i find the overall course extremely useful, thank you.

isaiahtokunbo
Автор

Hey, I am looking for a setup for test suites in NestJS, but with addition of factories for classes, in order to help me with seeding and "Arrange" Step of the Test. Any idea where to watch that?
Especially, for complex schemas where i.e. I want to test a module, which every entity depends on the creation of others.

dimitrisbellos
Автор

Hi, thanks for the video. I tried commenting the jwtguard parts in providers of the controller test file and even with the guard actives in the controller, the tests still pass so this part doesn't seem to do anything and the unit tests aren't blocked by the guard and stuff. Could you explain that ? Is it because the guards are actually blocking before entering the controller and here we are testing as if we are already in it ?

paulflmn
Автор

Hey ..I found this video so useful..Should we have to do the same for e2e testing with guards?

saravanakumarps
Автор

this tutorial is so useful, thank yoU! quick question - is it good practice to test separately or is it better to test them together in the controller test?
if separately, i have a hard time understanding how to write them as there aren't many examples out there it seems. if its good practice, may you also make a video for this? thank you so much in advance!

shecodeshk
Автор

video is really helpful thank you so much
i had a question, can we directly access the methods defined in services in the controller.spec.ts instead of mocking those functions ?

AjaySharma-vzei
Автор

Maybe I misunderstood the test but since you are mocking the create method call and return, what exactly is being tested?

SolidousMdz
join shbcf.ru