本文整理匯總了TypeScript中@angular/testing.TestComponentBuilder.createAsync方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript TestComponentBuilder.createAsync方法的具體用法?TypeScript TestComponentBuilder.createAsync怎麽用?TypeScript TestComponentBuilder.createAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular/testing.TestComponentBuilder
的用法示例。
在下文中一共展示了TestComponentBuilder.createAsync方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: async
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.createAsync(DashboardComponent).then(fixture => {
comp = fixture.debugElement.componentInstance;
expect(comp.heroes.length).toEqual(0,
'should not have heroes before OnInit');
});
})));
示例2: it
it('should render the title', (done) => {
return tcb.createAsync(DashboardComponent)
.then(fixture => {
let component = fixture.componentInstance;
component.title = 'Top_heroes';
fixture.detectChanges();
let element = fixture.nativeElement;
expect(element.querySelector('h3').innerText).toContain('Top_heroes');
done();
});
});
示例3: it
it('should render form', (done) => {
tcb.createAsync(LoginComponent)
.then((fixture) => {
let element = fixture.nativeElement;
fixture.detectChanges();
let form = element.querySelector('form');
expect(form).toBeTruthy();
expect(form.querySelector('input[name="username"]')).toBeTruthy();
expect(form.querySelector('input[name="password"]')).toBeTruthy();
done();
});
});
示例4: spyOn
(tcb: TestComponentBuilder, router: MockRouter) => {
let spy = spyOn(router, 'navigate').and.callThrough();
tcb.createAsync(DashboardComponent).then(fixture => {
let hero: Hero = {id: 42, name: 'Abbracadabra' };
comp = fixture.debugElement.componentInstance;
comp.gotoDetail(hero);
let linkParams = spy.calls.mostRecent().args[0];
expect(linkParams[0]).toEqual('HeroDetail', 'should nav to "HeroDetail"');
expect(linkParams[1].id).toEqual(hero.id, 'should nav to fake hero\'s id');
});
})));