Skip to content

Feature Request: Example how to test @defer -blocks #11046

@GipHub123

Description

@GipHub123

Hi, I'm not sure if this is a bug. I'm having trouble setting up a test case for a component with an @defer block using MockBuilder. Any insights?

@Component({
  selector: 'app-test',
  standalone: true,
  templateUrl: './test.component.html',
})
class TestComponent {
}


@defer (on viewport) {
  <div>text</div>
} @placeholder {
  <div>placeholder</div>
}

describe('TestComponent', () => {

  let fixture: ComponentFixture<TestComponent>;

  beforeEach(async () => {

    return MockBuilder(TestComponent)
      .beforeCompileComponents(testBed => {
        testBed.configureTestingModule({deferBlockBehavior: DeferBlockBehavior.Manual});
      });

  });

  beforeEach(async () => {

    fixture = TestBed.createComponent(TestComponent);

  });

  describe('template', () => {


    it('whenStable', async () => {

      await fixture.whenStable();

      const deferBlockFixtures: DeferBlockFixture[] = await fixture.getDeferBlocks();
      expect(deferBlockFixtures.length).toEqual(1);

    });

  });

});

Number of DeferBlockFixture seems always to be zero no matter How I set up the test case?

https://angular.dev/guide/templates/defer#testing-defer-blocks

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions