當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript testing_internal.ComponentFixture類代碼示例

本文整理匯總了TypeScript中angular2/testing_internal.ComponentFixture的典型用法代碼示例。如果您正苦於以下問題:TypeScript ComponentFixture類的具體用法?TypeScript ComponentFixture怎麽用?TypeScript ComponentFixture使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ComponentFixture類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

  describe('Router lifecycle hooks', () => {

    var tcb: TestComponentBuilder;
    var fixture: ComponentFixture;
    var rtr: Router;

    beforeEachProviders(() => TEST_ROUTER_PROVIDERS);

    beforeEach(inject([TestComponentBuilder, Router],
                      (tcBuilder: TestComponentBuilder, router: Router) => {
                        tcb = tcBuilder;
                        rtr = router;
                        cmpInstanceCount = 0;
                        log = [];
                        eventBus = new EventEmitter();
                      }));

    it('should call the routerOnActivate hook', inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
             .then((_) => rtr.navigateByUrl('/on-activate'))
             .then((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('activate cmp');
               expect(log).toEqual(['activate: null -> /on-activate']);
               async.done();
             });
       }));

    it('should wait for a parent component\'s routerOnActivate hook to resolve before calling its child\'s',
       inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
             .then((_) => {
               ObservableWrapper.subscribe<string>(eventBus, (ev) => {
                 if (ev.startsWith('parent activate')) {
                   completer.resolve(true);
                 }
               });
               rtr.navigateByUrl('/parent-activate/child-activate')
                   .then((_) => {
                     fixture.detectChanges();
                     expect(fixture.debugElement.nativeElement).toHaveText('parent {activate cmp}');
                     expect(log).toEqual([
                       'parent activate: null -> /parent-activate',
                       'activate: null -> /child-activate'
                     ]);
                     async.done();
                   });
             });
       }));

    it('should call the routerOnDeactivate hook', inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
             .then((_) => rtr.navigateByUrl('/on-deactivate'))
             .then((_) => rtr.navigateByUrl('/a'))
             .then((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('A');
               expect(log).toEqual(['deactivate: /on-deactivate -> /a']);
               async.done();
             });
       }));

    it('should wait for a child component\'s routerOnDeactivate hook to resolve before calling its parent\'s',
       inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
             .then((_) => rtr.navigateByUrl('/parent-deactivate/child-deactivate'))
             .then((_) => {
               ObservableWrapper.subscribe<string>(eventBus, (ev) => {
                 if (ev.startsWith('deactivate')) {
                   completer.resolve(true);
                   fixture.detectChanges();
                   expect(fixture.debugElement.nativeElement).toHaveText('parent {deactivate cmp}');
                 }
               });
               rtr.navigateByUrl('/a').then((_) => {
                 fixture.detectChanges();
                 expect(fixture.debugElement.nativeElement).toHaveText('A');
                 expect(log).toEqual([
                   'deactivate: /child-deactivate -> null',
                   'parent deactivate: /parent-deactivate -> /a'
                 ]);
                 async.done();
               });
             });
       }));

    it('should reuse a component when the routerCanReuse hook returns true',
       inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
             .then((_) => rtr.navigateByUrl('/on-reuse/1/a'))
//.........這裏部分代碼省略.........
開發者ID:ASLA1899,項目名稱:angular,代碼行數:101,代碼來源:lifecycle_hook_spec.ts

示例2: advance

function advance(fixture: ComponentFixture): void {
  tick();
  fixture.detectChanges();
}
開發者ID:844496869,項目名稱:angular,代碼行數:4,代碼來源:integration_spec.ts

示例3: expect

 .then((_) => {
   fixture.detectChanges();
   expect(fixture.debugElement.nativeElement).toHaveText('activate cmp');
   expect(log).toEqual(['activate: null -> /on-activate']);
   async.done();
 });
開發者ID:ASLA1899,項目名稱:angular,代碼行數:6,代碼來源:lifecycle_hook_spec.ts

示例4: expect

 .then((_) => {
   rootTC.detectChanges();
   expect(rootTC.debugElement.nativeElement).toHaveText('goodbye');
   expect(location.urlChanges).toEqual(['/bye']);
   async.done();
 });
開發者ID:LordBinary,項目名稱:angular,代碼行數:6,代碼來源:redirect_route_spec.ts

示例5: expect

 .then((_) => {
   fixture.detectChanges();
   expect(fixture.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
   async.done();
 });
開發者ID:ProjectFrank,項目名稱:angular,代碼行數:5,代碼來源:navigation_spec.ts


注:本文中的angular2/testing_internal.ComponentFixture類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。