本文整理汇总了TypeScript中angular2/testing.injectAsync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript injectAsync函数的具体用法?TypeScript injectAsync怎么用?TypeScript injectAsync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了injectAsync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('When loading the UserAppComponent', () => {
var mockRouterProvider: MockRouterProvider = new MockRouterProvider();
beforeEachProviders(() => {
return [mockRouterProvider.getProviders()];
});
it('should do something',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(UserAppComponent)
.then((fixture: ComponentFixture) => {
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
});
})
);
});
示例2: 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', injectAsync([TestComponentBuilder],
(tsb: TestComponentBuilder) => {
return 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');
});
}));
});
示例3: describe
describe('App', () => {
let fixture: ComponentFixture;
beforeEach(injectAsync([TestComponentBuilder], tcb => {
return tcb.createAsync(App)
.then(f => fixture = f);
}));
it('should have a title', () => {
// given a component instance
let appCmp = fixture.componentInstance;
// when we trigger the change detection
fixture.detectChanges();
// then we should have a name
let element = fixture.nativeElement;
expect(element.querySelector('h1')).toHaveText('Hello, Angular2!');
});
});
示例4: describe
describe('Testing Login Component Failed Flow', () => {
let mockRouterProvider = new MockRouterProvider();
beforeEachProviders(() => {
return [
provide(AuthService, {useClass: MockFailedAuthService}),
mockRouterProvider.getProviders(),
FormBuilder
];
});
it('Login should fail', injectAsync([TestComponentBuilder],
(tcb: TestComponentBuilder) => {
return tcb.createAsync(LoginComponent).then(fixture => {
const instance = fixture.debugElement.componentInstance;
instance.login();
chai.expect(instance.message).to.equal('Incorrect credentials.');
});
}));
});
示例5: describe
describe('DashboardComponent', () => {
beforeEachProviders(() => [
provide(Router, { useValue: {} }),
provide(SpeakerService, {
useValue: {
getSpeakers: () => { },
onDbReset: () => { }
}}),
ToastService
]);
it('should instantiate component',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(DashboardComponent).then(fixture => {
expect(fixture.componentInstance instanceof DashboardComponent).toBe(true, 'should create DashboardComponent');
});
}));
});
示例6: describe
describe('Search Tests', () => {
beforeEachProviders(() => [
HTTP_PROVIDERS,
provide(MainService, { useClass: MockMainService })
]);
it('should change if active', injectAsync([TestComponentBuilder], (tcb) => {
return tcb
.overrideProviders(
Search, [provide(MainService, { useClass: MockMainService })]
)
.createAsync(Search).then((fixture) => {
fixture.componentInstance.search('url');
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
expect(compiled.outerHTML).toContain('TTT');
});
}));
});
示例7: describe
describe('App component', () => {
// Support for testing component that uses Router
beforeEachProviders(() => [
RouteRegistry,
DirectiveResolver,
provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppComponent}),
provide(Router, {useClass: RootRouter})
]);
it('should work',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(TestComponent)
.then(rootTC => {
rootTC.detectChanges();
let appDOMEl = rootTC.debugElement.children[0].nativeElement;
expect(DOM.querySelectorAll(appDOMEl, 'c-app > c-navbar > nav > a')[1].href).toMatch(/http:\/\/localhost:\d+\/about/);
});
}));
});
示例8: describe
describe('SampleComponent', () => {
let fixture;
//setup
beforeEachProviders(() => [
TestComponentBuilder
]);
beforeEach(injectAsync([TestComponentBuilder], tcb => {
return tcb
.createAsync(TestComponent)
.then(f => fixture = f);
}));
it('should say something about making a library', () => {
let container = fixture.componentInstance,
div = fixture.nativeElement.querySelector('div');
expect(div.textContent).toBe('');
});
});
示例9: describe
describe('SanitizeDirective', () => {
let fixture;
//setup
beforeEachProviders(() => [
TestComponentBuilder
]);
beforeEach(injectAsync([TestComponentBuilder], tcb => {
return tcb
.createAsync(TestComponent)
.then(f => fixture = f);
}));
it('should add a class', () => {
let container = fixture.componentInstance,
div = fixture.nativeElement.querySelector('div');
expect(div.getAttribute('class')).toBe('sample-class');
});
});
示例10: describe
describe('AppComponent', () => {
beforeEachProviders(() => [
AppComponent
]);
it('should exist', inject([AppComponent], (appComponent:AppComponent) => {
expect(appComponent).toBeDefined();
}));
it('should render a header', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb.createAsync(AppComponent)
.then((fixture:ComponentFixture) => {
let element = fixture.nativeElement;
let appComponent = fixture.componentInstance;
fixture.detectChanges();
expect(element.querySelectorAll('h1').length).toBe(1);
});
}));
});