本文整理汇总了TypeScript中angular2/testing.async函数的典型用法代码示例。如果您正苦于以下问题:TypeScript async函数的具体用法?TypeScript async怎么用?TypeScript async使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了async函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
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"');
});
})));
});
示例2: describe
describe('TodolistComponent', () => {
it('should have been created successfully', async(inject([TestComponentBuilder],
(tcb: TestComponentBuilder) => {
tcb.createAsync(TestComponent).then((fixture) => {
testFixture = fixture;
fixture.detectChanges();
todoCompiled = fixture.nativeElement;
todolistCmp = fixture.debugElement
.children[0].componentInstance;
expect(todoCompiled).toBeDefined();
});
})));
it('should add todo successfully', () => {
todolistCmp.todo = new Todo('test', true);
todolistCmp.addTodo();
testFixture.detectChanges();
let items = todoCompiled.querySelectorAll('.list-group-item');
expect(items.length).toEqual(3);
let item = items[items.length - 1];
expect(item.querySelector('label').textContent).toEqual(' test');
expect(item.querySelector('input[type="checkbox"]').checked).toBeTruthy();
});
it('should delete todo successfully', () => {
todolistCmp.delTodo(0);
testFixture.detectChanges();
expect(todoCompiled.querySelectorAll('.list-group-item').length)
.toEqual(2);
});
});
示例3: describe
describe('ChildComponent', () => {
it('should print inputs correctly', async(inject([TestComponentBuilder],
(tsb: TestComponentBuilder) => {
tsb.createAsync(TestComponent).then((fixture) => {
testFixture = fixture;
testFixture.detectChanges();
childCompiled = testFixture.nativeElement;
childCmp = testFixture.debugElement.children[0].componentInstance;
expect(childCompiled).toBeDefined();
expect(childCmp).toBeDefined();
expect(childCompiled.querySelector('h6'))
.toHaveText('From parent');
expect(childCompiled.querySelector('h5'))
.toHaveText('Hello test');
});
})));
it('should trigger changeMe event correctly', () => {
childCmp.changeMe();
testFixture.detectChanges();
expect(childCmp.num).toEqual(1);
expect(childCompiled.querySelector('h6'))
.toHaveText('Changed from child. Count: ' + childCmp.num);
});
});
示例4: describe
describe('About Component', () => {
beforeEachProviders(() => []);
it('should ...', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
tcb.createAsync(About).then((fixture) => {
fixture.detectChanges();
});
})));
});
示例5: describe
describe('LoggedInOutlet Directive', () => {
beforeEachProviders(() => []);
it('should ...', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
tcb.createAsync(TestComponent).then((fixture) => {
fixture.detectChanges();
});
})));
});
示例6: describe
describe('SimplebindComponent', () => {
it('should have print "Simple" on template', async(inject([TestComponentBuilder],
(tsb: TestComponentBuilder) => {
tsb.createAsync(TestComponent).then((fixture) => {
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
expect(compiled).toBeDefined();
expect(compiled.querySelector('p'))
.toHaveText('Simple');
});
})));
});
示例7: describe
describe('Child Component', () => {
beforeEachProviders(() => [
provide(Router, { useClass: MockRouter }),
provide(RouteParams, { useClass: MockRouteParams }),
]);
it('should ...', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb.createAsync(ChildComponent).then((fixture: ComponentFixture) => {
fixture.detectChanges();
});
})));
});
示例8: describe
describe('With Hash', () => {
it('should add the provided class to the active element', async(inject([TestComponentBuilder, Router, LocationStrategy], (tcb, router$, ls) => {
ls.internalBaseHref = '#';
router$.next({
path: '/'
});
return compile(tcb, '<a linkActive="active" linkTo="/">Page</a>')
.then((fixture) => {
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
let link: Element = compiled.querySelector('a');
expect(link.getAttribute('class')).toEqual('active');
});
})));
});
示例9: describe
describe('x-large directive', () => {
// Create a test component to test directives
@Component({
template: '',
directives: [ XLarge ]
})
class TestComponent {}
it('should sent font-size to x-large', async(inject([TestComponentBuilder], (tcb) => {
return tcb.overrideTemplate(TestComponent, '<div x-large>Content</div>')
.createAsync(TestComponent).then((fixture: any) => {
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement.children[0];
expect(compiled.style.fontSize).toBe('x-large');
});
})));
});
示例10: describe
describe('AppComponent', () => {
beforeEachProviders(() => [
LoggerService,
ROUTER_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, { useValue: AppComponent }),
provide(ApplicationRef, { useClass: MockApplicationRef }),
provide(APP_BASE_HREF, { useValue: '/' }),
]);
it('should have brand Angular 2 Starter', async(inject([TestComponentBuilder],
(tsb: TestComponentBuilder) => {
tsb.createAsync(TestComponent).then((fixture) => {
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
expect(compiled).toBeDefined();
expect(compiled.querySelector('a.navbar-brand'))
.toHaveText('Angular 2 Starter');
});
})));
});