NestJs Testing Tutorial - Integration Testing

preview_player
Показать описание
In this video, I will be showing how to do integration testing in nestjs without mocking dependencies.

If you love this video consider leaving me a like to help with the youtube algorithm and subscribing if you haven't.

00:00 Integration Testing Introduction
06:20 Project structure
09:45 Test setup
10:00 Setting up Jest
18:00 Setting up testing environment
20:30 Push prisma migrations
21:30 createTodo() test
32:00 createUser() test

Closed captions sponsored by Prisma 😄
Рекомендации по теме
Комментарии
Автор

not working for me, database connection issue, cant listen error from db, pls help

ExperimentKing
Автор

Hi Vlad, It's a very nice feeling to write and thank you for all your videos, especially NestJS one's. They are very informatic and crystal clear. I am a backend developer working with express JS and Now when I received an opportunity from my organization to work on NestJS, your tutorials are really a life saver.
I would humbly request you to kindly prepare a tutorial on writing unit tests with Jest for NestJS and prisma application. Looking forward for this tutorial. Thanks

deveshsrivastava
Автор

Hey Vlad, I came from the FreeCodeCamp tutorial for NestJS. Great job BTW with that course. It was the least painful way to learn.

Hoping to learn more about other kinds of test as you mentioned some things being outside the scope of "that" video.

I was trying to continue with the bookmark app project here but I am a bit confused about the nature of integration testing.

If I have a service for creating a user in the user module.
0. Should I use that to create the user in the integration testing for the related data(todo, bookmark, etc...), or is it required to create a new user using the ORM (Prisma) directly?

I would really love to hear some of your thoughts about the approaches to take with integration testing on backend.

I am trying to figure out how Integration testing is different than other forms of testing (e2e in this case).

Really look forward to learning and getting into TDD so we can make certain CI/CD pipelines more robust in our organization. (It's held together by duct tape and a can debug attitude for now.)

So far the e2e testing is a no brainer as it help achieve large coverage of our entire API logic with which the front-end is going to interact with. (Majorly Rest Request)

Questions:

1. Should integration testing even be required for the NestJS application if we improve our code coverage in the e2e tests?

2. Should integration testing be done with the frontend (assuming we have to spin up a test server for this)?

3. If the end goal is to maintain all the functionality intact with newer features and account for more edge case, should an approach where the e2e test coverage is increased on both front-end and backend and can the dedicated "Integration" testing be prioritized lower?

Would love to hear more from you.

Cheers.

DevilDude
Автор

Hey Vlad, when using Prisma with Nest, should I be using the Prisma generated types or create my own DTO class with class-validator? The benefit with class-validator is that I can make sure a field is not empty or has a min/max length etc so in that case I prefer it but idk ... When it comes to filtering options or unique input fields, etc the Prisma generated types are really handy.

adamtak
Автор

hi, thank you for the best tutorial of integration tests on nest.
one question, can i add validation-class pipe to check dto?

ManuelZavattaCAS
Автор

Hey, excellent guide. However, I'm getting the error "TypeError: this[modelKey].deleteMany is not a function", the line "await prisma.cleanDatabase()". Do you know, how can I fix it?

vladyslavgooglya
Автор

Very useful video!! Thanks a lot for sharing

AT-mxbx
Автор

i watched your video on creating bookmarks with nestjs that had the e2e tests. i kept having listen EADDRINUSE: address already in use after i had created the first two tests for sign up and sign in apparently because app.close() does not seem to work well on windows. Is there a work around you know of? I cant seem to find a solution.

robertkwesiamoah
Автор

I have .env and .env.test each with a DATABASE_URL. I then give the database to Prisma using env(DATABASE_URL). The Databases are running but not using Docker.

When I run "prisma migrate dev" will the migrations between the two databases get mixed up or will Prisma know which database it did changes to? I'm worried that I could wipe my development database somehow and lose all the data.

Anteater
Автор

Well done. It's a classical way of testing I think, but ofc still kudos.

victordepta
Автор

Hello
Thanks for all the things you shared !

Can you please do a video on How to deploy NestJs app ?
Thanks a lot !

kevinterrier
Автор

If anyone encounters the error of property 'user' does not exist on prisma, just update the @prisma/client package to latest version.

debarghyachakraborty
Автор

I have this problem
"Cannot find module from 'app.e2e-spec.ts'"
I copy your jest-int but i have problem :(

rainbow-jwog
Автор

so integration test is basically doing testing of your code integration with other module/ 3rd party ?
the principle is to not trust the 3rd party that you integrating ?

I just don't get what the point of it because for sure prisma already run their own test suite to make sure their released code works
another thing is should you do integration test and e2e too or e2e can considered enough ?

rainedJMTi
Автор

Thanks a lot Vlad! Can you make a tutorial for GraphQL with Nest.js?

binov
Автор

TypeError: this[modelKey].deleteMany is not a function

31 | );
32 | // console.log(models.);
> 33 | return =>
| ^
34 | }
35 | }

dorrakadri
welcome to shbcf.ru