Learn How to Unit Test Angular's 17 Defer Block

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ม.ค. 2025

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

  • @CodeShotsWithProfanis
    @CodeShotsWithProfanis  ปีที่แล้ว

    It's always a challenge to create a video for a feature that is currently under development preview. Having said that, the default `DeferBlockBehavior` changed from Manual to `Playthrough` via this commit github.com/angular/angular/pull/53956.
    It's a great change since in most cases, as you will see in this video, the Playthrough is the winning option.

    • @paulh6933
      @paulh6933 ปีที่แล้ว +1

      Sorry, let me be a little more explicit. I think testing has been in the background, not much attention to it. Now we are seeing Cypress and Playwright making large strides. We also saw standalone. All of these making testing easier and more "enjoyable" (yea that might be a stretch). So I am eager to see more testing enhancements.

  • @madpwnz
    @madpwnz ปีที่แล้ว +1

    Cheers for the video mate.

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

    Nice, and do you perhaps in idea how we can mock components inside @defer blocks?
    When I talk about mocking components, I don't want to mock child component deps as well. I hoped ng-mocks helps me but not really

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

      Can you elaborate a bit more with an example?

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

      @@CodeShotsWithProfanis
      @defer { } @placeholder { }
      where the parent and the child are standalone, child has a service dependency and when I'm testing the parent component I would like to mock the child ofc because it is unit test. Before I used MockComponent() from ng-mocks.
      Is it understandable now?

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

      @@balintcsaszar6831 Can you try this?
      await TestBed.configureTestingModule({
      deferBlockBehavior: DeferBlockBehavior.Playthrough,
      imports: [ParentComponent, MockComponent(ChildComponent)],
      }).compileComponents();
      It seems that ng-mocks works fine

  • @paulh6933
    @paulh6933 ปีที่แล้ว

    Are you using the new @web/test-runner?

    • @CodeShotsWithProfanis
      @CodeShotsWithProfanis  ปีที่แล้ว +1

      In that video I am using karma but you can check this short video were I use web-test-runner
      th-cam.com/users/shorts2lLS6KEd_14

    • @paulh6933
      @paulh6933 ปีที่แล้ว +1

      Thanks I heard Karma was being deprecated. It will be interesting to see more on this topic

    • @CodeShotsWithProfanis
      @CodeShotsWithProfanis  ปีที่แล้ว +1

      ​@@paulh6933 There is also the alternative of Jest which is supported by Angular. There is a build for that. I could generate a video explaining this transition