NestJS Testing Tutorial | Unit and Integration Testing

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

КОМЕНТАРІ • 179

  • @jon1867
    @jon1867 3 роки тому +32

    Your Nest videos are easily the best I've seen. Could you do another one on testing where you set up a Development database using migrations, and then only do E2E testing with the database as a part of the testing.

    • @mariusespejo
      @mariusespejo  3 роки тому +14

      thanks! you’re thinking like a true full e2e where it actually writes to a db instead of mocking it out? Sure I can potentially make something for that

    • @jon1867
      @jon1867 3 роки тому +2

      @@mariusespejo I would absolutely love that. I spent my day setting up a docker and figuring out how to use a node environment to choose which one to spin up upon test. But I've been having a hell of a time with jest dependencies being all messed up for some reason.
      I appreciate you!

  • @isurumaldeniya9536
    @isurumaldeniya9536 3 роки тому +3

    Brother, you are a life savior. I look for many resources but couldn't find that overriding thing. Thanks so much, brother 😁👍👍 Subs to your channel

  • @MrSpiftire
    @MrSpiftire 3 роки тому +1

    Great introduction. I've been banging my head trying to get mocking to work while using typeDI and typeORM. Might just switch my whole backend to use NestJS after watching this =)

    • @mariusespejo
      @mariusespejo  3 роки тому

      great! I haven’t tried typeDI but if you’re definitely looking for a DI-based framework you can’t go wrong with nest, and it’s got great integration with typeorm so you’re also covered there

  • @R3flexx2001
    @R3flexx2001 3 місяці тому

    great work, very well explained. greetings from Argentina 🔵⚪🔵

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

    thanks for awesome tutorial video, watching your video with speed 1.5 is always my way for running through all of it then begin to coding :)))

    • @mariusespejo
      @mariusespejo  Рік тому +1

      Glad to know you can still understand me at 1.5x haha thanks!

  • @aomadeira
    @aomadeira 3 роки тому +1

    Great content you've provided here sir!
    Just wanna leave a quick note that if you've created a custom class for your Repository you'll have to write "provide: UserRepository," instead of "provide: getRepositoryToken(User),"
    Keep up the good work!

    • @mariusespejo
      @mariusespejo  3 роки тому

      thanks Anderson! good note, I haven’t actually tried making a custom class for repositories yet, will take a look at that

  • @mrarc197
    @mrarc197 3 роки тому +16

    I really miss git repository here :( Sometimes when you want to jump from file to file its really difficult to switch between different timestamps in video.

    • @mariusespejo
      @mariusespejo  3 роки тому +3

      thanks for you input, I do need to work on providing source code along with the content

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

      @@mariusespejo that would be greatly appreciated :)

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

    More great content. The music is cool and soothing to start, and glad you dropped it as the 'real' content started. :)

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

      Thanks! I mostly don’t add music in newer stuff, there’s a thin line between it being entertaining and potentially distracting

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

    @Marius Espejo, how to override multiple services in createTestingModule? My controller A is dependent on service B,C,D

  • @EstebanHelgueroCardiff
    @EstebanHelgueroCardiff 8 місяців тому

    Hi Marius! Question, should we always create a unit test for our service? Or should we just create an integrarion test? I want my test no to be related to the implementation only on the output of the service. What do uou think?

    • @mariusespejo
      @mariusespejo  8 місяців тому +1

      Having a mix of both is good but whether or not you should always do unit tests is up to you. If you had to pick one to focus on, definitely the integration tests are more valuable.

  • @dimitrisbellos01
    @dimitrisbellos01 3 місяці тому

    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.

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

    Great tutorial. Your efforts is truly appreciated

  • @АнтонВолков-ф3ъ
    @АнтонВолков-ф3ъ 2 роки тому

    thank you so much, you've put everything on the shelves.

  • @heartofcode5372
    @heartofcode5372 22 дні тому

    the amount of uncomitted files gives me anxiety :D
    on a serious note, great video :)
    do you happen to have this on github by any chance?

  • @lucascyrne6301
    @lucascyrne6301 3 роки тому +1

    Dude, you rock! Congratulations for your amazing work :)

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

    Lovely tutorial

  • @tusharroy6182
    @tusharroy6182 3 роки тому

    so clear, Thank you so much would like to see more of these.

    • @mariusespejo
      @mariusespejo  3 роки тому

      thanks Tushar! definitely more of these in the future. Anything specific you were hoping to be covered?

    • @tusharroy6182
      @tusharroy6182 3 роки тому

      @@mariusespejo A Project! I would be happy if you can build a project connecting all the topics that you have covered so far. Would be really awesome to see how these things work together. Thanks

  • @alexandermarthius5593
    @alexandermarthius5593 3 роки тому

    Crystal clear as usual, Great video Marius!

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

    Thanks man ... really nice groundwork for us to build on top. I'm enjoying myself doing some old school TDD (is this still a thing?) on an idea I'm having and one thing I'm trying to achieve is that in the name of the technique, iow the unit tests should drive how I design my units and the integration tests how I design my integrations. At the 27min mark, there is a comment on changes impacting the test code ... but wouldn't that be exactly the reason why you are writing them? I mean, you want to have an asset that tells you if any of the changes performed in your existing code base is breaking it, also, if the tests should be driving the design, then I would think it's a good idea to write them first and let them fail, then your redesign now has a very concrete objective, to pass the tests. This has limitations but seems pretty fun to do and makes writing tests much less cumbersome (and with a slight lesser feeling of worthlessness?) and one I can tell right away is that it should not dictate how the unit being tested will work, but instead rely on testing its Inputs and Outputs (Black Box Testing).

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

      Yeah some good points. Yes in general your tests should act as a safety net to capture any moment that you MIGHT have broken previous functionality. That is precisely the purpose of tests. However IDEALY your tests should not simply be a mirror of your exact implementation details. If I have a test that asserts something is created, it shouldn’t matter exactly HOW it was created. Otherwise you’re really just testing implementation details and that leads to brittle tests. That’s the point I was trying to make around the 26:50-27min mark, that in ideal terms I should be able to change the underlying query but as long as it still results in the same expected result, then my test should pass. That’s basically what you pointed out with black box testing so I’m not sure where the disconnect is, it sounds like we agree on the same core principle. However I was calling it out specifically because at that example unit test, if you mock the dependency, it’s a bit hard to create a mock that doesn’t ultimately behave or mirror your implementation details.
      Also this video was really more a lesson on how to setup tests for Nest specifically and not necessarily on TDD. However I actually do think TDD is a great practice, in general anything that promotes designing the API first in some way is a good thing

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

      @@mariusespejo thanks for the answer man, no disagreement indeed, I just fell the need to get that point you made and bring the TDD talk. Thanks again for the video man, much success!

  • @prashantpandey8281
    @prashantpandey8281 3 роки тому

    Great Video

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

    You saved my day. Thank you.

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

    Thank you kindly for this video.

  • @adamprice1169
    @adamprice1169 3 роки тому +1

    any chance of the starter code so people can follow quickly without much set up

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

    you are the best!, thank you!

  • @leofreiitas
    @leofreiitas 3 місяці тому

    Thank you, the unit test part was perfect, the e2e I would prefer not mocking anything, but thanks anyway for the good content

    • @mariusespejo
      @mariusespejo  3 місяці тому +1

      Yup I actually agree, overtime I’ve found it better to actually just run tests off of a real database to get e2e as close to real as possible, but it does require a little extra setup. thanks for stopping by to comment!

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

    Easy and helpful

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

    Hi Marius, following your video (e2e testing), I keep getting this error: Nest can't resolve dependencies of the JwtStrategy (AuthService, ?). Please make sure that the argument ConfigService at index [1] is available in the AuthModule context.
    I tried the overrideProvider for ConfigService, but no hope. Any ideas? Thank you

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

      That means you didn’t register the config module in your auth module. Alternatively you can register it globally docs.nestjs.com/techniques/configuration#use-module-globally

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

      @@mariusespejo It is registered globally in the appModule. I added it into the authModule and now I get: Nest can't resolve dependencies of the UserModel (?). Please make sure that the argument DatabaseConnection at index [0] is available in the MongooseModule context.

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

      I mean it’s telling you exactly what the problem is, the module you’re trying to use is missing dependencies. In a test not all of your modules are necessarily registered like in the real app, so it’s not able to find things. That means in your test you either need to add those missing dependencies in the test module, or you need to mock them

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

      @@mariusespejo Hi again, I resolved it by mocking configService. Thanks man :)

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

      Glad you got it figured out!

  • @rukeeojigbo2221
    @rukeeojigbo2221 3 роки тому

    Thanks a lot tried clicking the subscribe button to subscribe twice...

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

    Amazing Video!

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

    How to do e2e test on getManager().query(). While doing so, it always takes default connection

  • @connieleung96
    @connieleung96 3 роки тому

    Excellent tutorial. where were you 1 year ago? I had to learn testing the hard way.

    • @mariusespejo
      @mariusespejo  3 роки тому

      A year ago? likely being a bum and not making videos haha glad it helped you!

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

    Hey! thanks for the video!. Im trying to create test filed on an existing project, npx nest generate test place, place being the name of the module i want to test. I get "Invalid schematic "test". Please, ensure that "test" exists in this collection.". :/ Do i need to install it separately?

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

      Invalid schematic means it’s not supported for generate, you’ll just have to make the file manually.

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

    Really helpful tutorial, clear and straight forward. Thanks much!

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

    Great video buddy. I wrote my first unit test for one endpoint in a pretty fleshed out backend API, and it was over 136 lines long. Is that normal? I imagine that if i do the rest of the endpoints in the controller file it will reach to 500 lines-ish

    • @mariusespejo
      @mariusespejo  Рік тому +1

      A controller unit test generally should be short. Most of your business logic should be in services/providers meaning a controller should be pretty slim and unit tests of it in most cases just need to assert that it’s calling the right service methods (which can be mocked). The endpoint e2e tests I would expect to be quite a bit longer because you’re integrating all the things including authentication, authorization, validation, middlewares, then finally asserting expected status codes and body response, etc. The e2e test is where you’ll get the most value, specially if you keep mocks to a minimum

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

      @@mariusespejo thanks for the thoughtful response. I'll revisit the code and maybe try to get rid of sections. It makes sense as the controller only handles requests/responses.

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

    Thank you! This helped me a lot!

  • @bodolawale5448
    @bodolawale5448 3 роки тому

    Lovely video. Thanks A Lot

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

    Great content, and if I have logic in my service layer that can return errors like 404, 409, how do I test this in the controller and service layer?

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

      Lets say for example your service layer throws “EntityNotFound” which the controller catches so it can then throw NotFoundException. Then in your controller unit test the service mock for one of your tests bust be setup to throw EntityNotFound, then you can assert NotFoundException was thrown. Similar idea for the service. If you were doing an e2e test then similar idea but instead you’d actually assert that you got a 404 status response. Hope that helps

  • @grimmersnee
    @grimmersnee 3 роки тому

    nice explanation. How would you approach testing endpoints that have guards / decorators and interceptors etc..

    • @mariusespejo
      @mariusespejo  3 роки тому +1

      I would test them as usual and have those things run for real. However it depends on the underlying implementation behind those decorators. For example if you have an auth guard that integrates with an external identity provider, then I would either mock that guard or use a different passport strategy specifically for testing. RBAC guards I would definitely try to test for real, but that’s where your auth mock will come into play (e.g simulating different users with different roles).
      If you do need to mock any of it, there’s a small detail in the video where I briefly show that you can also do things like overrideGuard, overrideInterceptor, etc.

  • @ateebahmed2237
    @ateebahmed2237 3 роки тому

    Great content.

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

    Excellent video, love the way you explain things. So simplified, easy to go through and grasp knowledge. Have you consider doing Udemy courses? Cause I strongly believe people would like to aquire more depful content from you.

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

      Yeah I’ve thought about making paid courses, but for now it’s all just here for free :)

  • @РусланЮсуфов-ф3ш
    @РусланЮсуфов-ф3ш 3 роки тому

    Thank you very much, it helped a lot!

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

    Great video! Any idea on how to mock a request session using supertest? My controller pulls data off of the request session. I'd like to be able to mock that in my e2e test

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

      In theory you just need a mock middleware which puts data inside req.session, and that data could be whatever you want. Or otherwise maybe you could mock other parts of the pipeline, e.g. if you had a guard that checks data in session, you could mock that guard instead

  • @developerbythegraceofjesus4194
    @developerbythegraceofjesus4194 3 роки тому

    Yes for the end to end test so that your E2E tests act as a living documentation . Thanks

  • @mszado15
    @mszado15 3 роки тому

    GREAT. NICE JOB!!!

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

    27:10 One comment about the 'expect().toBeCalled()' assertions making the tests brittle.
    They already *are* brittle, because you are implicitly relying on the underlying implementation in your choice of which methods to define in your mockUserRepostory.
    For example, if you switched to using insert() and query() in the service, your mockUserRepository probably wouldn't have those methods defined, so the test would fail anyway.
    For a real life project, I am needing to effectively mock a lot of prisma in this manner. I'd also potentially like to be able to inject different provider overrides for different tests: any ideas how?
    Great tutorial though, thanks.

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

      Fair enough good point! I feel like mocking ORM/query builders in general always leads to that. I think the only way to get around that is by having an extra layer of abstraction so that you’re not dealing with the underlying implementation directly. E.g. for typeorm for example you can do custom repositories: orkhan.gitbook.io/typeorm/docs/custom-repository
      I imagine that would result in just needing to mock a single method from the repo.
      As for your override question, you can maybe use multiple describe blocks with their own test beds for each set of tests with different overrides. Not sure there’s a better way than that

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

      @@mariusespejo Thanks.
      And, of course, this is true of any dependency mocking. You try and mock the smallest part of the dependency's interface, but that means understanding the implementation details of the code under test.
      Eventually, you need a test suite to check that the mock implementation works correctly.

  • @PiyushChauhan2011
    @PiyushChauhan2011 3 роки тому

    Thanks what are your thoughts on testing the typeorm entities? How do we test db constraints in entity or add validation at entity level using class validator?

    • @mariusespejo
      @mariusespejo  3 роки тому

      You’re meant to utilize class validator on the dto not the entity, because you’re validating the data that’s coming in from a client not data coming out of the db which is what the entity classes represent. You can involve a real in-memory db if you wanted to but I don’t really see a ton of value in testing db constraints, it’s not your job to verify that the database is working as it’s supposed to. However that’s not to say that testing the integration with a real db is useless, there is value in doing a true end-to-end integration test. But the point is to test the integration not the individual database constraints

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

    Great video man, but I have a problem, I have a folder with multiples resources into, this called, phase-two, when I try to run any test file, doesn't work, show me a message about the Service Name can't be found it and other stuff. On the other hand, the first phase, called phase-one, doesn't have any issue, but in this folder the module is a same level of the test file generate by Nest. Do you know any solution for that?

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

      Generally in tests if it says it can’t find a dependency it’s because you test module didn’t include it (or a mock of it) so it doesn’t know what to inject, hence it will say can’t be found

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

      @@mariusespejo Thanks, I found a video where solved that problem.

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

    Hello, I have tried to do the video, but I try to connect to the DB all the time... my way is to simulate the service call, that

  • @alanrodriguezw.9149
    @alanrodriguezw.9149 3 роки тому

    Thanks You! Very Helful.

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

    Holy cow! its too good lecture. And I have a question. I am trying to do integration test. And my modules use axios. And then I got error which indicates that jest cannot parse axios. Can you give some suggestions on this ?

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

      Nest has an HTTP module @nestjs/axios which basically lightly wraps axios and you make requests via HttpService, meaning it’s something injected and can be easily mocked in tests. Anything that you use directly will be slightly harder to mock unless you want to mock it at the jest level (which can also do its own module mocking) vs at the nest level

  • @warraupe9373
    @warraupe9373 3 роки тому

    Very nice!

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

    do you have an example using prism?

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

    Hey man, in the first test example, how can I test if my validation with class-validator are working? example: test if my response have a status code of 400 if no nome is provided, if the message contain "no name provided"?
    I'm trying this, but I don't know how :(

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

      I actually did cover exactly how to do that in the video towards the end, make sure to watch the whole thing 🙂

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

    @27:40 integration tests begins

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

    thanks for a video!

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

    Hello Marius, Great tutorial.

  • @AlexanderDobrin-ov4wc
    @AlexanderDobrin-ov4wc Рік тому

    Could you suggest a clean way of how test db should be configured for tests. Sould entire database module be mocked, or just configuration file changed, or environment. How migration and seeds should be implemented. Maybe you know great article about all of this?

    • @mariusespejo
      @mariusespejo  Рік тому +1

      It depends entirely on how “real” you want it to be. You could literally spin up a database like mysql/postgres with docker for example and set it up in such a way that it starts fresh per test. Run migrations, seed data, trigger your queries and make your assertions, wipe the db, rinse repeat. But the tradeoff is complexity and tests running slower. It’s also more complex doing that on CI, depending on your setup. Next best thing, maybe the same thing but run sqlite in memory. Tradeoff is that if you’re not actually using sqlite in production then there are API and behavior differences compared to your real DB. Next option is mocking the database layer entirely, perhaps at the ORM level. It’s easier, you don’t have to deal with migrations, tests are quick. But the tradeoff is your tests are the farthest away from being “real”. So it all boils down to how much confidence do you want your tests to produce and how complex of a setup are you willing to put up with

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

    In unit test, I saw that mostly we mock everything just to get the expected result, but if we mock something it for sure to be an expected result right ?
    I am curious let say in my service method contains some logic,
    how will this code be tested ? or is that we dont really need to test it ?
    most of unit testing video/ tutorial only showthe case where the service method that is simple,
    like have single line of code and mock dependency method that being called.
    What if I have a service method as below
    logic(input): {
    // do something with input example data transformation
    return input.toUpperCase();
    }
    when we write
    expect(service.logic(input)).toEqual(expectedResult);
    is that method really executed ? meaning it really call the exact service.logic method and return an upper case of the input ?

    • @mariusespejo
      @mariusespejo  3 роки тому +1

      We mock the dependencies but not the actual underlying logic of the thing your testing. In your example you’d unit the service by making sure that the output is transformed, your example would require zero mocking. But let’s say it uses a repository to select the input from the database, then your service logic uppercases it prior to returning, then your mock repository should return some mock return value and you would assert that you not only got the mock value but also that it’s all uppercase

  • @atilaaugusto_
    @atilaaugusto_ 3 роки тому

    great content!

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

    You were making integration tests but the file names had "end to end" is that right? I know it's just the name, but it confuses me a little bit 😆

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

      technically speaking e2e IS an integration test, it just happens to to cover the entire flow end to end like from a user’s perspective them making a request and getting a response back

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

    on the service tests, your mock implementation of create() is not creating an id. i don't know why the test of it passes.

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

      Create() doesn’t create the ID, the save does (which is where inserting would actually happen). And you should notice that the save mock does have ID creation in it. That’s why the test passes

  • @ivanmiarkulau8320
    @ivanmiarkulau8320 3 роки тому

    thanks a lot for this guide!

  • @ta3113ta
    @ta3113ta 3 роки тому

    thank you so much.

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

    perfect man

  • @vceolin3908
    @vceolin3908 3 роки тому

    AWESOME VIDEO, THANK YOU SO MUCH!
    subscribed also

  • @be3otech
    @be3otech 8 місяців тому

    Great tutorial. and can you put repo link please to make it doc for me ?

  • @МихаилЧон
    @МихаилЧон 3 роки тому

    Great

  • @creative-commons-videos
    @creative-commons-videos 3 роки тому

    does this testing work same for both REST and GraphQL endpoints ?

    • @mariusespejo
      @mariusespejo  3 роки тому +1

      yes should be mostly the same concepts for graphql endpoints but the key difference is for your e2e tests they will always be a POST with a request body containing the query

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

    Great tutorial, really helped me with mocking my repository on the test file. I have really been struggling with it. I have a question though. How do I override a guard in my controller and also override a provider at the same time. I tried .overrideProvider().overrideGuards() but it didn't work and I kept getting the error "Property 'overrideProvider' does not exist on type 'OverrideBy'.". I would really appreciate your guidance on how to go about it. Thank you

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

      You missing a few things there, you need to do something like this: .overrideProvider(MyService).useValue(myServiceMock).overrideGuard(MyGaurd).useValue(myGuardMock)
      Basically you need to tell it HOW to do the override. I think there is also .useClass() as an alternative to useValue() if your mock is a class and not an instance/object

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

      @@mariusespejo worked like a charm. Thanks alot, you literally saved the day 😅

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

      Great!!

  • @భాస్కర్నాగశ్రీనివాస్రేపురి

    Very useful video, can you provide git repo

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

    Please can you share your code or repo
    Thanks. Your content is amazing

  • @alexanderzharkov6953
    @alexanderzharkov6953 3 роки тому +1

    That was really helpful for me. I discovered so many things about testing and now feel like I'm ready to write these tests. I have a question: what code editor theme have you been using during this video? ;) Isn't the Night owl?

    • @mariusespejo
      @mariusespejo  3 роки тому

      glad to hear! yep it is night owl 🦉 Also have been trying github dark in some of my newer vids

  • @JustinMorganYXX
    @JustinMorganYXX 3 роки тому

    VS Code TS Auto-Import setting in preferences: Typescript > Preferences > Import Module Specifier. :)

    • @mariusespejo
      @mariusespejo  3 роки тому

      Ah thanks didn’t know there was setting for that lol

    • @JustinMorganYXX
      @JustinMorganYXX 3 роки тому

      @@mariusespejo I coincidentally had the same issue this week. Glad I could help.

  • @istbanane
    @istbanane 3 роки тому

    Is it possible to test the API with the database? Probably with e2e?

    • @mariusespejo
      @mariusespejo  3 роки тому +1

      yeah I don’t see why not. You might want to use something that’s in memory though like sqlite or something and you’ll need to make sure the database is wiped for each test. You likely will also need to migrate and/or seed per test.

    • @istbanane
      @istbanane 3 роки тому

      @@mariusespejo Thank you very much. The videos are great.

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

    Is this a junior, mid or senior tutorial?

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

      Are you asking about dev titles? Those honestly don’t mean anything in terms of your ability to learn

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

    e2e is equal/same to integration test?

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

      E2e is an integration test, but an integration test doesn’t always need to be end-to-end if that makes sense

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

    @Marius you can simply configure jest to use the same import strategy as vs code with the following config
    ```
    "jest": {
    "moduleFileExtensions": [
    "js",
    "json",
    "ts"
    ],
    "rootDir": "./",
    "modulePaths": [
    ""
    ],
    "testRegex": "spec.ts$",
    "transform": {
    "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
    "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
    }
    ```

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

      Ahh thanks for the tip!

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

      @@mariusespejo your welcome :)

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

      @@mariusespejo Btw, have you found a way to use a vscode plugin to run the test? I would love to have a better interface for reviewing the test and see what values was returned and so on.

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

      There is a jest vs code extension that I tried before that can do something like that but I wasn’t a fan of it. If you google vs code jest it’ll be the first result

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

      @@mariusespejo I also tried that one out, but it is pretty slow compared to just using the cli tool, I was hoping I had missed some gold right in front of my eyes :)

  • @alessandrorhomberg5366
    @alessandrorhomberg5366 3 роки тому

    It would be nice to have a tutroial about NestJS Authentication, Authorization (Claims-based authorization) :)

    • @mariusespejo
      @mariusespejo  3 роки тому

      I do have one for authentication in my channel

    • @alessandrorhomberg5366
      @alessandrorhomberg5366 3 роки тому

      @@mariusespejo I've already seen a really good tutorial. Would be cool if you went even more deeply into the subject of authentification and authorization.
      like RBAC and CASL

  • @alexandercuartas830
    @alexandercuartas830 3 роки тому

    Yo, thanks a lot for the video

  • @rohmatmret8265
    @rohmatmret8265 3 роки тому +2

    can you share code in github ..?

  • @DodaGarcia
    @DodaGarcia 3 роки тому

    I'm having that same problem with the autoimport!! It's a pain

    • @DodaGarcia
      @DodaGarcia 3 роки тому

      That said, E2E tests aren't usually meant to use a mock repository, but a fully provisioned test version of it that's as close to the production setup as possible.
      I started working with NestJs very recently and love how it keeps the code organized, but it's not very helpful in creating integration tests, only unit (total isolation) and E2E (close to production). I supposed E2E tests do technically count as integration tests though, so it's not a huge deal either.

    • @mariusespejo
      @mariusespejo  3 роки тому

      Yeah I would consider e2e as integration. Also you can run e2e tests with an actual db if you really wanted to, e.g. a sqlite for example, but you’d have to migrate/seed and wipe the db before/after each test. That added overhead/complexity may or may not be worth it depending on your use case or preference

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

    why are we doing this? Like we anyways implemented fake function and will implement functional in service that will contain bugs

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

      You might be mocking the dependencies but you’re still testing that the logic in your functions are producing the intended results. The examples here might be too simple to fully see the value of it, I was mostly showing the HOW but I recommend reading about the WHY

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

      @@mariusespejo okay thanks

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

    please provide this video git Repo for more understanding

  • @ahheask9527
    @ahheask9527 7 місяців тому

    Have source code in github?

  • @AliHaider-ep1hy
    @AliHaider-ep1hy 2 роки тому

    can i have the link to your github repo??

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

    if you're making a mock service that has fake methods. what are you even testing? how is this useful?

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

      Well the point of unit tests is to isolate and typically provide mock dependencies. Is it able to function in isolation? I’m just explaining how to do it. Whether or not that’s useful to you is up to you. But it’s the entire point of dependency injection, to be able to easily inject alternative dependencies (e.g. mocks in this case) I do think the e2e tests are where most of the value is, specially if you minimize mocks and setup a real db so that you don’t have to mock the queries. But you need a little bit more setup for that, e.g. you need to be able to reset your database for each test. How much you actually mock is ultimately up to you, e.g. how much of a unit vs integration test do you want to do.

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

    Yo

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

      Sup

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

      @@mariusespejo I don’t know about testing, should you be doing end to end testing with unit testing ?

  • @user-pe5qr2wp4u
    @user-pe5qr2wp4u 2 роки тому

    useless without code//

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

      You mean the code that’s recorded? Lol

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

    PASS src/modules/users/controllers/users.controll.spec.ts
    ● Console
    console.log
    debug: Logging initialized at debug level {"timestamp":"10-02-2023 13:00:10"}
    at Console.log (node_modules/winston/lib/winston/transports/console.js:79:23)
    at async Promise.all (index 4)
    at async Promise.all (index 9)
    my app when I running test. its pass the test but it not log the test text. can you help me.

  • @syrlmhmd
    @syrlmhmd 3 роки тому

    You saved my day, thank you.