0

I am testing a component that has a query list of @ContentChildren. In my component these are accessible in the 'AfterContentInit` life cycle hook. But, when i intend to access the same in my spec file, my query list return me with an empty arrays.

I am trying to test the component without creating any mock component as it is done in this link. I have tried the solution provided in the link below but that didn't work for me.

Angular 2 unit testing - @ViewChild is undefined

In my Component:

    @ContentChildren(GetTemplateDirective) public templates: QueryList<GetTemplateDirective<AccordionTemplate>>;

In the component's spec file:

    it('should show the custom icon when the external template is passed', async(function () {
       accordionFixture.detectChanges();
       accordionComponent.ngAfterContentInit();
       console.log(accordionComponent.templates);
       expect(component.templates.toArray().length).toBeGreaterThan(0);
    }));
user3875919
  • 303
  • 1
  • 2
  • 13

1 Answers1

0

You can query using debug element :

 const debugEl = fixture.debugElement;
 debugEl.query(By.directive(AccordionTemplate));
Ankit Kapoor
  • 1,615
  • 12
  • 18