2016-09-13 14:39:39 -07:00
|
|
|
// #docplaster
|
2016-12-05 11:46:53 -08:00
|
|
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
2016-09-13 14:39:39 -07:00
|
|
|
import { By } from '@angular/platform-browser';
|
|
|
|
import { DebugElement } from '@angular/core';
|
|
|
|
|
|
|
|
import { BannerComponent } from './banner.component';
|
|
|
|
|
2016-12-05 11:46:53 -08:00
|
|
|
describe('BannerComponent (templateUrl)', () => {
|
2016-09-13 14:39:39 -07:00
|
|
|
|
2016-12-05 11:46:53 -08:00
|
|
|
let comp: BannerComponent;
|
|
|
|
let fixture: ComponentFixture<BannerComponent>;
|
|
|
|
let de: DebugElement;
|
|
|
|
let el: HTMLElement;
|
|
|
|
|
|
|
|
// #docregion async-before-each
|
|
|
|
// async beforeEach
|
|
|
|
beforeEach(async(() => {
|
2016-09-13 14:39:39 -07:00
|
|
|
TestBed.configureTestingModule({
|
|
|
|
declarations: [ BannerComponent ], // declare the test component
|
2016-12-05 11:46:53 -08:00
|
|
|
})
|
|
|
|
.compileComponents(); // compile template and css
|
|
|
|
}));
|
|
|
|
// #enddocregion async-before-each
|
2016-09-13 14:39:39 -07:00
|
|
|
|
2016-12-05 11:46:53 -08:00
|
|
|
// #docregion sync-before-each
|
|
|
|
// synchronous beforeEach
|
|
|
|
beforeEach(() => {
|
2016-09-13 14:39:39 -07:00
|
|
|
fixture = TestBed.createComponent(BannerComponent);
|
|
|
|
|
|
|
|
comp = fixture.componentInstance; // BannerComponent test instance
|
|
|
|
|
2016-09-23 02:03:20 -07:00
|
|
|
// query for the title <h1> by CSS element selector
|
|
|
|
de = fixture.debugElement.query(By.css('h1'));
|
|
|
|
el = de.nativeElement;
|
2016-09-13 14:39:39 -07:00
|
|
|
});
|
2016-12-05 11:46:53 -08:00
|
|
|
// #enddocregion sync-before-each
|
2016-09-13 14:39:39 -07:00
|
|
|
|
|
|
|
it('no title in the DOM until manually call `detectChanges`', () => {
|
2016-09-23 02:03:20 -07:00
|
|
|
expect(el.textContent).toEqual('');
|
2016-09-13 14:39:39 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should display original title', () => {
|
2016-12-05 11:46:53 -08:00
|
|
|
fixture.detectChanges();
|
2016-09-23 02:03:20 -07:00
|
|
|
expect(el.textContent).toContain(comp.title);
|
2016-09-13 14:39:39 -07:00
|
|
|
});
|
|
|
|
|
2016-12-05 11:46:53 -08:00
|
|
|
it('should display a different test title', () => {
|
2016-09-13 14:39:39 -07:00
|
|
|
comp.title = 'Test Title';
|
|
|
|
fixture.detectChanges();
|
2016-12-05 11:46:53 -08:00
|
|
|
expect(el.textContent).toContain('Test Title');
|
2016-09-13 14:39:39 -07:00
|
|
|
});
|
2016-12-05 11:46:53 -08:00
|
|
|
|
2016-09-13 14:39:39 -07:00
|
|
|
});
|