本文整理汇总了TypeScript中@angular/core/testing.getTestInjector函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getTestInjector函数的具体用法?TypeScript getTestInjector怎么用?TypeScript getTestInjector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getTestInjector函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('PersonsDetailsComponent', () => {
if( !getTestInjector().platformProviders.length )
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS)
let fixture: ComponentFixture<PersonsDetailsComponent>
beforeEachProviders(() => [
TestComponentBuilder,
provide(Http, {useValue: {}})
])
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(PersonsDetailsComponent)
.then(rootFixture => fixture = rootFixture)
}))
it('must be a list of persons list', () => {
let component = fixture.componentInstance
let element = fixture.nativeElement
fixture.detectChanges()
expect(element.querySelectorAll('li').length).toBe(5)
expect(element.querySelector('li').innerText).toBe('Max Smith')
})
})
示例2: it
it('should allow to use a custom live element', fakeAsyncTest(() => {
let customLiveEl = document.createElement('div');
// We need to reset our test injector here, because it is already instantiated above.
getTestInjector().reset();
getTestInjector().addProviders([
provide(LIVE_ANNOUNCER_ELEMENT_TOKEN, {useValue: customLiveEl}),
MdLiveAnnouncer
]);
let injector = getTestInjector().createInjector();
let liveService: MdLiveAnnouncer = injector.get(MdLiveAnnouncer);
liveService.announce('Custom Element');
// This flushes our 100ms timeout for the screenreaders.
tick(100);
expect(customLiveEl.textContent).toBe('Custom Element');
}));
示例3: describe
describe('GreeterComponent', () => {
if( !getTestInjector().platformProviders.length )
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS)
it('must be "Phone Book App"',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(GreeterComponent)
.then((fixture: ComponentFixture<GreeterComponent>) => {
let element = fixture.nativeElement
fixture.detectChanges()
expect(element.querySelectorAll('h1').length).toBe(1);
expect(element.querySelector('h1').innerText).toBe('Phone Book App');
})
}))
)
})
示例4: describe
describe('Router tests', () => {
if( !getTestInjector().platformProviders.length )
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS)
let router: Router
let spylocation: SpyLocation
//setup
beforeEach(() => {
addProviders([
RouteRegistry,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppComponent}),
provide(Location, {useClass: SpyLocation}),
provide(Router, {useClass: RootRouter}),
])
})
beforeEach(inject([Router, Location], (r, l) => {
router = r
spylocation = l
}))
//specs
it('Should be able to navigate to Home', done => {
router.navigate(['PersonList']).then(() => {
expect(spylocation.path()).toBe('')
done()
}).catch(e => done.fail(e))
})
it('should redirect not registered urls to Home', done => {
router.navigateByUrl('/unknown').then(() => {
expect(spylocation.path()).toBe('')
done()
}).catch(e => done.fail(e))
})
it('Should be able to navigate to About', done => {
router.navigate(['About']).then(() => {
expect(spylocation.path()).toBe('/about')
done()
}).catch(e => done.fail(e))
})
})