当前位置: 首页>>代码示例>>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;未经允许,请勿转载。