本文整理匯總了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))
})
})