当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript testing.getTestInjector函数代码示例

本文整理汇总了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')
    })
})
开发者ID:pracxs,项目名称:angular-2-sofia,代码行数:27,代码来源:details.component.spec.ts

示例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');
  }));
开发者ID:Angular2-BD,项目名称:material2,代码行数:21,代码来源:live-announcer.spec.ts

示例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');
                })
        }))
    )   
})
开发者ID:georgema1982,项目名称:angular-2-intro,代码行数:18,代码来源:greeter.component.spec.ts

示例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))
  })
})
开发者ID:georgema1982,项目名称:angular-2-intro,代码行数:44,代码来源:router.spec.ts


注:本文中的@angular/core/testing.getTestInjector函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。