• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript testing.getTestInjector函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript testing.inject函数代码示例发布时间:2022-05-28
下一篇:
TypeScript testing.getTestBed函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap