#Test Defer Blocks in Child Component

2 messages · Page 1 of 1 (latest)

lone ether
#

I have MyComp that contains @defer blocks. This component is tested with a wrapper component:

@Component({
  template: `
<my-comp></my-comp>`,
  standalone: true,
  imports: [
    MyComp,
  ],
})
class WrapperComponent {}

describe('MyComp', () => {
  let wrapper: WrapperComponent;
  let fixture: ComponentFixture<WrapperComponent>;
  let component: MyComp;
  let deferBlocks: Array<DeferBlockFixture>;

  beforeEach(waitForAsync(() => {
    TestBed.configureTestingModule({
      imports: [
        WrapperComponent,
      ],
      deferBlockBehavior: DeferBlockBehavior.Manual,
    })
      .compileComponents();
  }));

  beforeEach(async () => {
    fixture = TestBed.createComponent(WrapperComponent);
    wrapper = fixture.componentInstance;
    deferBlocks = await fixture.getDeferBlocks();
    fixture.detectChanges();

    const de = fixture.debugElement.query(By.directive(MyComp));
    component = de.componentInstance;
  });

deferBlocks from the wrapper is just an empty array. de doesn't seem to have anything on it that gives access to MyComp's defer blocks.

lone ether
#

okay figured it out, the defer blocks aren't available until after fixture.detectChanges()