Rob Wormald recognized that we had no plunker for a simple component test. Inspired improved learning path for testing including: * Add plunkers for both inline and external template versions of the simplest `BannerComponent` * Added the banner-specs for that purpose and also a quickstart-specs in the setup folder * Adjusted prose in testing and setup-systemjs-anatomy to call these out * Moved testing of external template spec earlier in the guide because it is likely to be needed right away. * Add comments on the optional "testing" folder and corrects var names to match * Leaves Jasmine Spec Runner output visible when tests finish
34 lines
962 B
TypeScript
34 lines
962 B
TypeScript
import { AppComponent } from './app.component';
|
|
|
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
import { By } from '@angular/platform-browser';
|
|
import { DebugElement } from '@angular/core';
|
|
|
|
describe('AppComponent', function () {
|
|
let de: DebugElement;
|
|
let comp: AppComponent;
|
|
let fixture: ComponentFixture<AppComponent>;
|
|
|
|
beforeEach(async(() => {
|
|
TestBed.configureTestingModule({
|
|
declarations: [ AppComponent ]
|
|
})
|
|
.compileComponents();
|
|
}));
|
|
|
|
beforeEach(() => {
|
|
fixture = TestBed.createComponent(AppComponent);
|
|
comp = fixture.componentInstance;
|
|
de = fixture.debugElement.query(By.css('h1'));
|
|
});
|
|
|
|
it('should create component', () => expect(comp).toBeDefined() );
|
|
|
|
it('should have expected <h1> text', () => {
|
|
fixture.detectChanges();
|
|
const h1 = de.nativeElement;
|
|
expect(h1.innerText).toMatch(/angular/i,
|
|
'<h1> should say something about "Angular"');
|
|
});
|
|
});
|