How do I test and mock Standalone Components

แชร์
ฝัง

ความคิดเห็น • 40

  • @dylanjhalltech8313
    @dylanjhalltech8313 8 หลายเดือนก่อน +1

    I really enjoyed this video because you took a problem, demonstrated why it happens, demonstrated a solutions with explanation - then provided information on a third party product. With this video I learned so much, even beyond testing

  • @harshranjan8784
    @harshranjan8784 8 หลายเดือนก่อน +1

    Great tutorial! Was able to finally understand how to inject mocks for standalone stuff. Thanks 😁

    • @RainerHahnekamp
      @RainerHahnekamp  8 หลายเดือนก่อน

      Great to hear, you're welcome

  • @rororlo
    @rororlo 3 หลายเดือนก่อน

    I've been fighting against this problem for hours, thanks for the video, all really clear!

  • @pazzuto
    @pazzuto 4 หลายเดือนก่อน

    This is great content as always. The concern I have about moving to standalone components is the bundle size. I haven't taken a deep look into this, but I've read here and there that there's a lot of code duplicated and your app actually grows in size. I'm sure it can be mitigated with lazy loading, but it's something to consider.

    • @RainerHahnekamp
      @RainerHahnekamp  4 หลายเดือนก่อน

      Hi, where did you hear about the bundle size issue?
      Could it be that you are mistake standalone with the barrel files? Having a lot of barrel files (index.ts) will problems to your bundler because it might not be able to tree-shake them efficientyl, and you may end up with a huge initial bundle.
      Regarding Standalone vs NgModule, there is no impact on the bundle size.

  • @MichaelSmallDev
    @MichaelSmallDev 8 หลายเดือนก่อน

    I just ran into a situation like this today but with component store in a child component being the troublesome thing. I think this solution will work a lot better than what I tried to do. Thanks.

    • @RainerHahnekamp
      @RainerHahnekamp  8 หลายเดือนก่อน

      You're welcome Michael! Happy to help.

  • @yaibanoutsukushii
    @yaibanoutsukushii 8 หลายเดือนก่อน

    another great explanation! thank you!
    it's embarassing but in my company we got new schematics using overrideCopmonents and I just did not bother finding out why... sometimes the test did not work and then I spend hours trying out different things. So happy I now understand, what it does!

    • @RainerHahnekamp
      @RainerHahnekamp  8 หลายเดือนก่อน

      Yeah, so TestBed.override... is something we don't see that often but it is quite powerful

  • @paevents8064
    @paevents8064 8 หลายเดือนก่อน

    Awesome, great explanation. This is what I was looking for

  • @olegsytnik
    @olegsytnik หลายเดือนก่อน

    By the way, MockComponents from ng-mocks work just as well, and your tests look clearer

    • @RainerHahnekamp
      @RainerHahnekamp  หลายเดือนก่อน

      Isn't that what I show at the end of the video?

  • @VinitNeogi
    @VinitNeogi 8 หลายเดือนก่อน

    Indepth Info as always, thanks Rainer

  • @rudyxxdevxx7323
    @rudyxxdevxx7323 8 หลายเดือนก่อน

    Thanks Rainer, awesome video !

    • @RainerHahnekamp
      @RainerHahnekamp  8 หลายเดือนก่อน

      You are very welcome Rudy

  • @Nabulio85
    @Nabulio85 2 หลายเดือนก่อน

    Thank you.
    Great content 🙏

  • @danywalls
    @danywalls 6 หลายเดือนก่อน

    Amazing content as always!!!!!

    • @RainerHahnekamp
      @RainerHahnekamp  6 หลายเดือนก่อน

      Thanks Dany and best wishes!

  • @NicolasMaas
    @NicolasMaas 7 หลายเดือนก่อน

    You mention the usage of ng-mocks library to Mock Standalone Components. We use this as wel to mock our services that we provide. However, sometimes, it uses the actual service instead of the mocked one. How do you properly mock these services that you provide?

    • @RainerHahnekamp
      @RainerHahnekamp  7 หลายเดือนก่อน

      Hi, could it be the case that those services are provided by the component? Otherwise, it has to work as expected. Can you maybe provide an example?

    • @NicolasMaas
      @NicolasMaas 7 หลายเดือนก่อน

      @@RainerHahnekamp The services are indeed all provided on the component itself.

  • @dimasavenkov2951
    @dimasavenkov2951 8 หลายเดือนก่อน

    How about non-standalone dependencies? I have in my imports array some modules with related dependencies. I want to replace them with stubs which I already have. Should I create test module and include all stubs components in it and add it to the standalone imports?

    • @RainerHahnekamp
      @RainerHahnekamp  8 หลายเดือนก่อน

      So you will always have to configure the TestingModule. There is no other way if you want to test via the DOM (and it is also the official recommendation). Without standalone, mocking is easier. you just declare your stubs instead the original ones. Declare, not import.

  • @rolandjost3823
    @rolandjost3823 8 หลายเดือนก่อน

    Very good thanks...

  • @dmytroukrainskiy
    @dmytroukrainskiy 8 หลายเดือนก่อน

    Thanks for video)

  • @besara_
    @besara_ 7 หลายเดือนก่อน

    how to test Angular Guards ?

    • @RainerHahnekamp
      @RainerHahnekamp  7 หลายเดือนก่อน +1

      Do you want to test only the guards or the guard in combination with a Component?
      In the first case, check out this video th-cam.com/video/mMiSmStwGOU/w-d-xo.html, in the second that one: th-cam.com/video/DsOxW9TKroo/w-d-xo.html

    • @besara_
      @besara_ 7 หลายเดือนก่อน

      @@RainerHahnekamp really, appreciated 👏

  • @paulh6933
    @paulh6933 8 หลายเดือนก่อน

    Cool!!!

  • @chapin4.129
    @chapin4.129 25 วันที่ผ่านมา

    I have a problem with a dialog that is standalone, which returns this error TypeError: Cannot read properties of undefined (reading 'find') at Dialog.getDialogById (node_modules/@angular/cdk/fesm2022/dialog.mjs:506:33), has anyone encountered this error?

    • @RainerHahnekamp
      @RainerHahnekamp  24 วันที่ผ่านมา

      It would be great if you could offer some stackblitz example for reproduction.