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


TypeScript testing.TestContext類代碼示例

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


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

示例1: xdescribe

  xdescribe('UserEditPage', () => {

    var ctx:TestContext;

    var cmpDebugElement:DebugElement;

    var routeParams:RouteParams;

    beforeEachProviders(() => {
      routeParams = jasmine.createSpyObj('routeParams', ['get']);

      return [
        APP_TEST_PROVIDERS,
        provide(RouteParams, {useValue: routeParams}),
      ]
    });
    beforeEach(createTestContext(_  => ctx = _));

    beforeEach(done => {
      ctx.init(TestCmp)
        .finally(done)
        .subscribe(() => {
          cmpDebugElement = ctx.fixture.debugElement.query(By.directive(UserEditPage));
        }, console.error);
    });

    it('can be shown', () => {
      expect(cmpDebugElement).toBeTruthy();
    });

  });
開發者ID:windwang,項目名稱:angular2-app,代碼行數:31,代碼來源:UserEditPage.spec.ts

示例2: describe

  describe('SecurityRouterOutlet', () => {

    var ctx:TestContext;

    beforeEachProviders(() => [
      APP_TEST_PROVIDERS,
      provide(ROUTER_PRIMARY_COMPONENT, {useValue: TestCmp}),
    ]);
    beforeEach(createTestContext(_ => ctx = _));

    describe('when not signed in', () => {
      beforeEach(done => {
        ctx.init(TestCmp)
          .finally(done)
          .subscribe();
      });

      it('allows the access to public page', (done) => {
        ctx.router.navigate(['/PublicCmp']).then(() => {
          expect(ctx.location.path()).toEqual('/public');
          done();
        });
      });

      it('force redirect to login page when accessed to private page', (done) => {
        ctx.router.navigate(['/PrivateCmp']).then(() => {
          ctx.router.subscribe(() => {
            expect(ctx.location.path()).toEqual('/login');
            done();
          });
        });
      });
    }); // when not signed in

    describe('when signed in', () => {
      beforeEach(signin());
      beforeEach(done => {
        ctx.init(TestCmp)
          .finally(done)
          .subscribe();
      });

      it('allows the access to private page', (done) => {
        ctx.router.navigate(['/PrivateCmp']).then(() => {
          expect(ctx.location.path()).toEqual('/private');
          done();
        });
      });

      it('force redirect to specified page when accessed to a page like login page', (done) => {
        ctx.router.navigate(['/Login']).then(() => {
          ctx.router.subscribe(() => {
            expect(ctx.location.path()).toEqual('/public');
            done();
          });
        });
      });
    }); // when signed in

  });
開發者ID:windwang,項目名稱:angular2-app,代碼行數:60,代碼來源:SecurityRouterOutlet.spec.ts

示例3: describe

describe('Gravatar', () => {

  var ctx:TestContext;
  var cmpDebugElement:DebugElement;

  beforeEachProviders(() => [
    APP_TEST_PROVIDERS,
    provide(ROUTER_PRIMARY_COMPONENT, {useValue: App}),
  ]);
  beforeEach(createTestContext(_ => ctx = _));
  beforeEach(done => {
    ctx.init(TestCmp)
      .finally(done)
      .subscribe(() => {
        cmpDebugElement = ctx.fixture.debugElement.query(By.directive(Gravatar));
      });
  });

  it('can be shown', () => {
    expect(cmpDebugElement).toBeTruthy();

    const cmp:Gravatar = cmpDebugElement.componentInstance;
    expect(cmp.email).toEqual('test@test.com');
    expect(cmp.alt).toEqual('test-alt');
    expect(cmp.size).toEqual('1');

    const el = cmpDebugElement.nativeElement;
    expect(DOM.querySelector(el, 'img').getAttribute('src'))
      .toEqual('https://secure.gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=1');
  });

});
開發者ID:gtostock,項目名稱:angular2-app,代碼行數:32,代碼來源:Gravatar.spec.ts

示例4: describe

describe('HomePage', () => {

  var ctx:TestContext;

  var cmpDebugElement:DebugElement;
  var userStatsDebugElement:DebugElement;
  var micropostNewDebugElement:DebugElement;
  var feedDebugElement:DebugElement;

  beforeEachProviders(() => [
    APP_TEST_PROVIDERS,
    provide(ROUTER_PRIMARY_COMPONENT, {useValue: App}),
  ]);
  beforeEach(createTestContext(_ => ctx = _));

  function createCmp(done) {
    ctx.init(TestCmp)
      .finally(done)
      .subscribe(() => {
        cmpDebugElement = ctx.fixture.debugElement.query(By.directive(HomePage));
        if (!cmpDebugElement) return;
        userStatsDebugElement = cmpDebugElement.query(By.directive(UserStats));
        micropostNewDebugElement = cmpDebugElement.query(By.directive(MicropostNew));
        feedDebugElement = cmpDebugElement.query(By.directive(Feed));
      });
  }

  beforeEach(createCmp);

  it('can be shown', () => {
    expect(cmpDebugElement).toBeTruthy();
    expect(userStatsDebugElement).toBeTruthy();
    expect(userStatsDebugElement.componentInstance.userId).toEqual('me');
    expect(micropostNewDebugElement).toBeTruthy();
    expect(feedDebugElement).toBeTruthy();
  });

  it('reload user stats when created new micropost', () => {
    const userStats:UserStats = userStatsDebugElement.componentInstance;
    spyOn(userStats, 'ngOnChanges');
    micropostNewDebugElement.triggerEventHandler('created', null);
    expect(userStats.ngOnChanges).toHaveBeenCalled();
  });

  it('reload feed when created new micropost', () => {
    const feed:Feed = feedDebugElement.componentInstance;
    spyOn(feed, 'list');
    micropostNewDebugElement.triggerEventHandler('created', null);
    expect(feed.list).toHaveBeenCalled();
  });

  it('reload user stats when deleted a micropost', () => {
    const userStats:UserStats = userStatsDebugElement.componentInstance;
    spyOn(userStats, 'ngOnChanges');
    feedDebugElement.triggerEventHandler('deleted', null);
    expect(userStats.ngOnChanges).toHaveBeenCalled();
  });

});
開發者ID:mauricio1990silva,項目名稱:angular2-app,代碼行數:59,代碼來源:HomePage.spec.ts

示例5: createCmp

 function createCmp(done) {
   ctx.init(TestCmp)
     .finally(done)
     .subscribe(() => {
       cmpDebugElement = ctx.fixture.debugElement.query(By.directive(UserList));
     });
 }
開發者ID:gtostock,項目名稱:angular2-app,代碼行數:7,代碼來源:UserList.spec.ts

示例6: beforeEach

 beforeEach((done) => {
   ctx.init(TestCmp)
     .finally(done)
     .subscribe(() => {
       cmpDebugElement = ctx.fixture.debugElement.query(By.directive(HelpPage));
     });
 });
開發者ID:mauricio1990silva,項目名稱:angular2-app,代碼行數:7,代碼來源:HelpPage.spec.ts

示例7: beforeEach

 beforeEach(done => {
   ctx.init(TestCmp)
     .finally(done)
     .subscribe(() => {
       cmpDebugElement = ctx.fixture.debugElement.query(By.directive(UserEditPage));
     }, console.error);
 });
開發者ID:windwang,項目名稱:angular2-app,代碼行數:7,代碼來源:UserEditPage.spec.ts

示例8: beforeEach

 beforeEach(done => {
   ctx.backend.connections.subscribe(conn => {
     conn.mockRespond(new Response(new BaseResponseOptions()));
   });
   ctx.init(TestCmp)
     .finally(done)
     .subscribe(() => {
       cmpDebugElement = ctx.fixture.debugElement.query(By.directive(FollowBtn));
     });
 });
開發者ID:windwang,項目名稱:angular2-app,代碼行數:10,代碼來源:FollowBtn.spec.ts

示例9: createCmp

 function createCmp(done) {
   ctx.backend.connections.subscribe(conn => {
     conn.mockRespond(dummyResponse);
   });
   ctx.init(TestCmp)
     .finally(done)
     .subscribe(() => {
       cmpDebugElement = ctx.fixture.debugElement.query(By.directive(Feed));
     });
 }
開發者ID:mauricio1990silva,項目名稱:angular2-app,代碼行數:10,代碼來源:Feed.spec.ts

示例10: createCmp

 function createCmp(done) {
   ctx.init(TestCmp)
     .finally(done)
     .subscribe(() => {
       cmpDebugElement = ctx.fixture.debugElement.query(By.directive(HomePage));
       if (!cmpDebugElement) return;
       userStatsDebugElement = cmpDebugElement.query(By.directive(UserStats));
       micropostNewDebugElement = cmpDebugElement.query(By.directive(MicropostNew));
       feedDebugElement = cmpDebugElement.query(By.directive(Feed));
     });
 }
開發者ID:mauricio1990silva,項目名稱:angular2-app,代碼行數:11,代碼來源:HomePage.spec.ts


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