NestJs Testing Tutorial - Integration Testing

Поділитися
Вставка
  • Опубліковано 22 жов 2024

КОМЕНТАРІ • 29

  • @Alex-bc3xe
    @Alex-bc3xe Рік тому

    I am a big fan of Docker and Nest JS and of course Angular for the frontend and you are really good at Nest JS thx a lot.

  • @deveshsrivastava2718
    @deveshsrivastava2718 Рік тому

    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

  • @DevilDude
    @DevilDude 2 роки тому +6

    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.

    • @mrs013
      @mrs013 2 роки тому

      I would like to know the answer too

  • @adamtak3128
    @adamtak3128 2 роки тому +2

    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.

  • @ManuelZavattaCAS
    @ManuelZavattaCAS 10 місяців тому

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

  • @victordepta4069
    @victordepta4069 2 роки тому +1

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

  • @ExperimentKing78
    @ExperimentKing78 5 місяців тому

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

  • @AT-mx3bx
    @AT-mx3bx 2 роки тому

    Very useful video!! Thanks a lot for sharing

  • @robertkwesiamoah
    @robertkwesiamoah 9 місяців тому

    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.

  • @Anteater23
    @Anteater23 2 місяці тому

    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.

  • @kevinterrier5893
    @kevinterrier5893 2 роки тому

    Hello
    Thanks for all the things you shared !
    Can you please do a video on How to deploy NestJs app ?
    Thanks a lot !

  • @rainbow-jw3og
    @rainbow-jw3og 2 роки тому

    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 :(

  • @vladyslavgooglya9902
    @vladyslavgooglya9902 Рік тому +2

    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?

  • @DelaAnthonio
    @DelaAnthonio 2 роки тому

    What font do you use in your editor?

  • @anankondec
    @anankondec 2 роки тому

    Как всегда ТОП!)

  • @rained23JMTi
    @rained23JMTi 2 роки тому

    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 ?

    • @CodeWithVlad
      @CodeWithVlad  2 роки тому +2

      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).

    • @rained23JMTi
      @rained23JMTi 2 роки тому

      @@CodeWithVlad thanks that help a lot.

    • @CodeWithVlad
      @CodeWithVlad  2 роки тому

      @@rained23JMTi You're welcome!

  • @binov5012
    @binov5012 2 роки тому

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

  • @debarghyachakraborty
    @debarghyachakraborty 2 роки тому +1

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

    • @CodeWithVlad
      @CodeWithVlad  2 роки тому +1

      I think the error comes from the fact that npx prisma generate was not run :)

    • @debarghyachakraborty
      @debarghyachakraborty 2 роки тому +1

      @@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.

  • @dorrakadri1474
    @dorrakadri1474 6 місяців тому

    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 | }

    • @lukabeograd
      @lukabeograd 6 місяців тому +1

      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);
      }),
      );
      }