title: Angular 2.0.0-rc.1: How to test elements on the view or content (e.g. @ViewChildren, @ContentChildren)
body: <p>I have a component that gets data from a service which creates children on the <code>View</code>. Those children are only available when the <code>View</code> is created. In my example below the <code>View</code> is not created before it reaches its tests, thus test 2 fails.</p>
  
  <p>component:</p>
  
  <pre><code>@Component({
    selector: 'component-to-test',
    providers: [Service],
    directives: [NgFor, ChildComponent],
    template: `
      &lt;child [data]="childData" *ngFor="let childData of data"&gt;&lt;/child&gt;
  })
  
  export class ComponentToTest implements OnInit {
    @ViewChildren(ChildComponent) children: QueryList&lt;ChildComponent&gt;;
    private data: any;
  
    public ngOnInit() {
      this.getData();
    }
  
    private getData() {
      // async fetch data from a service
    }
  }
  </code></pre>
  
  <p>spec:</p>
  
  <pre><code>describe('ComponentToTest', () =&gt; {
    beforeEach(inject([ComponentToTest], (component: ComponentToTest) =&gt; {
      component.ngOnInit();
    }));
  
  
    it('should initialise data', inject([ComponentToTest], (component: ComponentToTest, service: Service) =&gt; {
      return service.getData().toPromise().then(() =&gt; {
        expect(component.data).toBeDefined();
      })
    }));
  
    it('should initialise children', inject([ComponentToTest], (component: ComponentToTest, service: Service) =&gt; {
      return service.getData().toPromise().then(() =&gt; {
        expect(component.children).toBeDefined();
      })
    }));
  });
  </code></pre>
  
  <p>Test 1 passes, test 2 fails. How do you test something that is created after the <code>View</code> or <code>Content</code> is initialised?</p>