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
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.
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?
it is because the models can include non-prisma models, so you have to map them correctly, here is my code : const models = Reflect.ownKeys(this).filter( (key) => key[0] !== '_' && typeof key === 'string' && /^[a-z]/.test(key) && typeof this[key].deleteMany === 'function', );
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.
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.
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.
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 ?
So to me, integration necessarily means testing several modules together, as opposed to unit testing where external modules would be mocked. Whether modules would have a database is up to you though. In my case if i'm running integration testing I would probably set it up and leave mocking to unit testing. I haven't seen that many projects with full test coverage, most of them have a very basic test coverage. In most cases an e2e would be enough. Usually e2e + unit tests and mocks is already great. Testing is not a science. Depending of your use cases you will have edge cases where you would need to run certain tests in a certain way. So to summarize. Unit tests help you to write your code, enforce standards and make sure you haven't made silly mistakes in your function. E2E testing tests your application as a whole. It does not test all the possible flows. E2E is heavy. Integration testing is useful if you want to test a certain subset of your application in more detail (say you have users with 5 different roles and you want to make sure that every user can do certain actions).
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
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.
I would like to know the answer too
not working for me, database connection issue, cant listen error from db, pls help
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?
me too
Me three
I modify this and fixed for me:
const models = Reflect.ownKeys(this).filter(
(key) => key[0] !== '_' && typeof key === 'string' && /^[a-z]/.test(key),
);
it is because the models can include non-prisma models, so you have to map them correctly,
here is my code :
const models = Reflect.ownKeys(this).filter(
(key) =>
key[0] !== '_' &&
typeof key === 'string' &&
/^[a-z]/.test(key) &&
typeof this[key].deleteMany === 'function',
);
Very useful video!! Thanks a lot for sharing
hi, thank you for the best tutorial of integration tests on nest.
one question, can i add validation-class pipe to check dto?
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.
Well done. It's a classical way of testing I think, but ofc still kudos.
What font do you use in your editor?
Hello
Thanks for all the things you shared !
Can you please do a video on How to deploy NestJs app ?
Thanks a lot !
I have this problem
"Cannot find module 'src/modules/auth/auth.module' from 'app.e2e-spec.ts'"
I copy your jest-int but i have problem :(
Как всегда ТОП!)
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.
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.
If anyone encounters the error of property 'user' does not exist on prisma, just update the @prisma/client package to latest version.
I think the error comes from the fact that npx prisma generate was not run :)
@@CodeWithVlad I tried that a few times but it always gave red squiggly in the client file. It worked only after I updated it. Don't know why.
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 ?
So to me, integration necessarily means testing several modules together, as opposed to unit testing where external modules would be mocked. Whether modules would have a database is up to you though. In my case if i'm running integration testing I would probably set it up and leave mocking to unit testing. I haven't seen that many projects with full test coverage, most of them have a very basic test coverage. In most cases an e2e would be enough. Usually e2e + unit tests and mocks is already great. Testing is not a science. Depending of your use cases you will have edge cases where you would need to run certain tests in a certain way.
So to summarize. Unit tests help you to write your code, enforce standards and make sure you haven't made silly mistakes in your function. E2E testing tests your application as a whole. It does not test all the possible flows. E2E is heavy. Integration testing is useful if you want to test a certain subset of your application in more detail (say you have users with 5 different roles and you want to make sure that every user can do certain actions).
@@CodeWithVlad thanks that help a lot.
@@rained23JMTi You're welcome!
Thanks a lot Vlad! Can you make a tutorial for GraphQL with Nest.js?
Yes, it's planned!
TypeError: this[modelKey].deleteMany is not a function
31 | );
32 | // console.log(models.);
> 33 | return Promise.all(models.map((modelKey) => this[modelKey].deleteMany()));
| ^
34 | }
35 | }
async cleanDatabase() {
if (process.env.APP_ENVIRONMENT === 'production') return;
const tables = [
'users',
//Other tables
];
await Promise.all(
tables.map(async (table) => {
const query = Prisma.sql`DELETE FROM ${Prisma.raw(table)} CASCADE;`;
await this.$executeRaw(query);
}),
);
}