describe('AppComponent with TCB', function () { beforeEach(() => { TestBed.configureTestingModule({declarations: [AppComponent]}); }); it('should instantiate component', () => { let fixture = TestBed.createComponent(AppComponent); expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent'); }); it('should have expected <h1> text', () => { let fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred expect(h1.innerText).toMatch(/angular app/i, '<h1> should say something about "Angular App"'); }); });
describe('AppComponent with TCB', function () { it('should instantiate component', async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { tcb.createAsync(AppComponent).then(fixture => { expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent'); }); }))); it('should have expected <h1> text', async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { tcb.createAsync(AppComponent).then(fixture => { // fixture.detectChanges(); // would need to resolve a binding but we don't have a binding let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred expect(h1.innerText).toMatch(/angular 2 app/i, '<h1> should say something about "Angular 2 App"'); }); }))); });
describe('AppComponent', function () { var de; var comp; var fixture; beforeEach(testing_1.async(function () { testing_1.TestBed.configureTestingModule({ declarations: [app_component_1.AppComponent] }) .compileComponents(); })); beforeEach(function () { fixture = testing_1.TestBed.createComponent(app_component_1.AppComponent); comp = fixture.componentInstance; de = fixture.debugElement.query(platform_browser_1.By.css('h1')); }); it('should create component', function () { return expect(comp).toBeDefined(); }); it('should have expected <h1> text', function () { fixture.detectChanges(); var h1 = de.nativeElement; expect(h1.innerText).toMatch(/angular/i, '<h1> should say something about "Angular"'); }); });