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


TypeScript testing.createTestContext函数代码示例

本文整理汇总了TypeScript中app/testing.createTestContext函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createTestContext函数的具体用法?TypeScript createTestContext怎么用?TypeScript createTestContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了createTestContext函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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

示例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: 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

示例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: describe

  describe('LoginPage', () => {

    var ctx:TestContext;
    var cmpDebugElement:DebugElement;
    var loginService:LoginService;

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

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

    it('can login', (done) => {
      const cmp:LoginPage = cmpDebugElement.componentInstance;
      spyOn(loginService, 'login').and.callThrough();
      ctx.backend.connections.subscribe(conn => {
        conn.mockRespond(new Response(new BaseResponseOptions()));
      });
      cmp.login('test@test.com', 'secret');
      expect(loginService.login).toHaveBeenCalledWith('test@test.com', 'secret');
      ctx.router.subscribe(() => {
        expect(ctx.location.path()).toEqual('/home');
        done();
      });
    });

    it('can navigate to signup page', (done) => {
      const el = cmpDebugElement.nativeElement;
      DOM.querySelector(el, 'a').click();
      ctx.router.subscribe(() => {
        expect(ctx.location.path()).toEqual('/signup');
        done();
      });
    });

  });
开发者ID:windwang,项目名称:angular2-app,代码行数:51,代码来源:LoginPage.spec.ts

示例6: describe

describe('relationship.UserList', () => {

  var ctx:TestContext;
  var cmpDebugElement: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(UserList));
      });
  }

  beforeEach(createCmp);

  it('can be shown', () => {
    ctx.fixture.detectChanges();

    expect(cmpDebugElement).toBeTruthy();

    const cmp:UserList = cmpDebugElement.componentInstance;
    expect(cmp.users.length).toEqual(2);

    expect(DOM.querySelectorAll(cmpDebugElement.nativeElement, '.users>li').length).toEqual(2);

    const gravatarDebugElement = cmpDebugElement.query(By.directive(Gravatar));
    expect(gravatarDebugElement).toBeTruthy();
    expect(gravatarDebugElement.componentInstance.alt).toEqual('test1');
    expect(gravatarDebugElement.componentInstance.email).toEqual('test1@test.com');

    const userLink:HTMLElement = cmpDebugElement.query(By.css('.users>li>a')).nativeElement;
    expect(userLink.innerText).toEqual('test1');
    expect(userLink.getAttribute('href')).toEqual('/users/1');
  });

  it('can load more', () => {
    const cmp:UserList = cmpDebugElement.componentInstance;
    const moreBtn = DOM.querySelector(cmpDebugElement.nativeElement, '.moreBtn');
    spyOn(cmp, 'listProvider').and.callThrough();
    moreBtn.click();
    expect(cmp.users.length).toEqual(4);
    expect(cmp.listProvider).toHaveBeenCalledWith({maxId: 100, count: 5});
  });

});
开发者ID:gtostock,项目名称:angular2-app,代码行数:51,代码来源:UserList.spec.ts

示例7: describe

describe('HelpPage', () => {

  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(HelpPage));
      });
  });

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

});
开发者ID:mauricio1990silva,项目名称:angular2-app,代码行数:24,代码来源:HelpPage.spec.ts

示例8: describe

  describe('TopPage', () => {

    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(TopPage));
      });
    });

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

      const signupLink = cmpDebugElement.query(By.css('a')).nativeElement;
      expect(signupLink.getAttribute('href')).toEqual('/signup');
    });

  });
开发者ID:windwang,项目名称:angular2-app,代码行数:24,代码来源:TopPage.spec.ts

示例9: describe

describe('Feed', () => {

  var ctx:TestContext;
  var cmpDebugElement:DebugElement;
  var micropostService:MicropostService;

  beforeEachProviders(() => [
    APP_TEST_PROVIDERS,
    provide(ROUTER_PRIMARY_COMPONENT, {useValue: App}),
  ]);
  beforeEach(createTestContext(_ => ctx = _));
  beforeEach(inject([MicropostService], _ => {
    micropostService = _;
  }));
  beforeEach(() => jasmine.clock().mockDate(new Date(24 * 60 * 60 * 1000)));

  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));
      });
  }

  beforeEach(createCmp);

  it('can show feed', () => {
    expect(cmpDebugElement).toBeTruthy();

    const cmp:Feed = cmpDebugElement.componentInstance;
    expect(cmp.feed.length).toEqual(2);

    const el = cmpDebugElement.nativeElement;
    expect(getDOM().querySelectorAll(el, 'li .content').length).toEqual(2);

    const avatarLink = getDOM().querySelector(el, 'li>a');
    expect(avatarLink.getAttribute('href')).toEqual('/users/1');

    const gravatarDebugElement = cmpDebugElement.query(By.directive(Gravatar));
    expect(gravatarDebugElement).toBeTruthy();
    expect(gravatarDebugElement.componentInstance.email).toEqual('test1@test.com');
    expect(gravatarDebugElement.componentInstance.alt).toEqual('test user1');

    const userLink = getDOM().querySelector(el, '.user>a');
    expect(userLink.innerHTML).toEqual("test user1");
    expect(userLink.getAttribute('href')).toEqual('/users/1');

    const content = getDOM().querySelector(el, '.content');
    expect(content.innerHTML).toEqual('content1');

    const timestamp = getDOM().querySelector(el, '.timestamp');
    expect(timestamp.innerText).toMatch(/1 day ago/);

    const deleteLinks = getDOM().querySelectorAll(el, '.delete');
    expect(deleteLinks[0]).toBeTruthy();
    expect(deleteLinks[1]).toBeFalsy();
  });


  it('does not delete micropost when not confirmed', () => {
    const deleteLink = getDOM().querySelector(cmpDebugElement.nativeElement, '.delete');
    spyOn(window, 'confirm').and.returnValue(false);
    spyOn(micropostService, 'delete');
    deleteLink.click();
    expect(micropostService.delete).not.toHaveBeenCalled();
  });

  it('deletes micropost when confirmed', done => {
    const cmp:Feed = cmpDebugElement.componentInstance;
    const testCmp:TestCmp = ctx.fixture.debugElement.componentInstance;
    const deleteLink = getDOM().querySelector(cmpDebugElement.nativeElement, '.delete');
    spyOn(window, 'confirm').and.returnValue(true);
    spyOn(cmp, 'list');
    spyOn(testCmp, 'listenDeleted');
    ObservableWrapper.subscribe(cmp.deleted, () => {
      expect(cmp.list).toHaveBeenCalled();
      expect(testCmp.listenDeleted).toHaveBeenCalled();
      done();
    });
    deleteLink.click();
  });

});
开发者ID:mauricio1990silva,项目名称:angular2-app,代码行数:86,代码来源:Feed.spec.ts

示例10: describe

describe('SignupPage', () => {

  var ctx:TestContext;

  var cmpDebugElement:DebugElement;
  var loginService:LoginService;

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

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

  it('can validate inputs', () => {
    const page:SignupPage = cmpDebugElement.componentInstance;
    page.name.updateValue('a', {});
    page.email.updateValue('b', {});
    page.password.updateValue('c', {});
    page.passwordConfirmation.updateValue('d', {});
    expect(page.myForm.valid).toBeFalsy();
    page.name.updateValue('akira', {});
    page.email.updateValue('test@test.com', {});
    page.password.updateValue('secret123', {});
    page.passwordConfirmation.updateValue('secret123', {});
    expect(page.myForm.valid).toBeTruthy();
  });

  it('can signup', (done) => {
    const page:SignupPage = cmpDebugElement.componentInstance;
    spyOn(loginService, 'login').and.callThrough();
    ctx.backend.connections.subscribe(conn => {
      conn.mockRespond(new Response(new BaseResponseOptions()));
    });
    page.onSubmit({
      email: 'test@test.com',
      password: 'secret',
      name: 'akira',
    });
    expect(loginService.login).toHaveBeenCalledWith('test@test.com', 'secret');

    ctx.router.subscribe(() => {
      expect(ctx.location.path()).toEqual('/home');
      done();
    });
  });

});
开发者ID:gtostock,项目名称:angular2-app,代码行数:61,代码来源:SignupPage.spec.ts


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