I am trying to understand more about Angular2 unit testing. Currently I am unable to get a count of a particular element in my component html template.
My component
import { Component, OnInit } from '@angular/core';
@Component({
  moduleId: module.id,
  selector: 'cl-header',
  templateUrl: 'cl-header.component.html',
  styleUrls: ['cl-header.component.css']
})
export class ClHeaderComponent implements OnInit {
  headerTitle: string = 'Some Title';
  constructor() {}
  ngOnInit() {
  }
}
The component html template
<nav class="navbar navbar-default" role="navigation">
  <ul class="nav navbar-nav">
    <li><a href="#" class="fa fa-bars fa-2x"></a></li>
    <li><a href="http://localhost:91/UserHome/" class="fa fa-home fa-2x no-padding"></a></li>
  </ul>
  <div class="nav navbar-text-center">{{headerTitle}}</div>
  <a href="#" class="navbar-brand pull-right">
    <img src="app/components/cl-header/shared/logo.png" height="28px" alt="logo" />
  </a>
  <i>testtext</i>
</nav>
My Spec File
import {
  beforeEach,
  beforeEachProviders,
  describe,
  expect,
  it,
  inject,
  injectAsync
} from '@angular/core/testing';
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
import { Component } from '@angular/core';
import { By } from '@angular/platform-browser';
import { ClHeaderComponent } from './cl-header.component';
describe('Component: ClHeader', () => {
  it('should display header title: "Some Title"', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
    return tcb.createAsync(ClHeaderComponent).then((fixture) => {
      fixture.detectChanges();
      var compiled = fixture.debugElement.nativeElement;
      //WORKING
      //To check that a given piece of text exists in the html template
      //expect(compiled.innerHTML).toContain('ul');
      //To check whether a given element type contains text
      //expect(compiled.querySelector('div')).toHaveText('Some Title');
      //END WORKING
      //NOT WORKING - ALWAYS RETURNS SUCCESS NO MATTER WHAT THE TOEQUAL COUNT IS          
      //To check that a given element by type exists in the html template
      expect(compiled.querySelector('div').length).toEqual(5);
    });
  }));
});No matter what I set the toEqual expression to below: expect(compiled.querySelector('div').length).toEqual(5);
The test will always return true.
Does anyone have any advice on how to accurately get a count of a given element type in a component html template?
Thanks

querySelectorAll('div').length.lengthproperty. Next, did you disable caching in your browser? Open developer tools usually helps with this.compiled.querySelector('div').lengthwill thrown an exception.