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

TypeScript testing.TestComponentBuilder类代码示例

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

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



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

示例1: Promise

 (tcb: TestComponentBuilder, router: Router, angulartics2: Angulartics2) => {
   return tcb.overrideTemplate(RootCmp, `<div [angulartics2On]="'click'" [angularticsEvent]="'InitiateSearch'" [angularticsCategory]="'Search'"></div>`)
     .createAsync(RootCmp)
     .then((rtc) => fixture = rtc)
     .then((_) => {
       fixture.detectChanges();
       return new Promise((resolve) => {
         expect(EventSpy).not.toHaveBeenCalled();
         angulartics2.eventTrack.subscribe((x: any) => EventSpy(x));
         compiled = fixture.debugElement.nativeElement.children[0];
         compiled.click();
         resolve();
       });
     })
     .then((_) => {
       fixture.detectChanges();
       return new Promise((resolve) => {
         setTimeout(() => {
           expect(EventSpy).toHaveBeenCalledWith({ action: 'InitiateSearch', properties: { category: 'Search', eventType: 'click' } });
           resolve();
         });
       });
     });
 }));
开发者ID:jamescarter-le,项目名称:angulartics2,代码行数:24,代码来源:angulartics2On.spec.ts


示例2: describe

  describe('Sidenav', () => {
    let builder: TestComponentBuilder;
    let service: SidenavService;

    function setup(template: string = null): Promise<ITestFixture> {
      let prep = template === null ?
        builder.createAsync(TestComponent) :
        builder.overrideTemplate(TestComponent, template).createAsync(TestComponent);
      return prep.then((fixture: ComponentFixture) => {
        fixture.detectChanges();
        let debug = fixture.debugElement.query(By.css('md-sidenav'));
        let cdebug = fixture.debugElement.query(By.css('md-sidenav-container'));
        return {
          fixture: fixture,
          component: debug.componentInstance,
          debug: debug,
          cdebug: cdebug,
          container: cdebug ? cdebug.componentInstance : null
        };
      }).catch(console.error.bind(console));
    }

    beforeEach(inject([TestComponentBuilder, SidenavService], (tcb, serv) => {
      builder = tcb;
      service = serv;
    }));

    describe('md-sidenav', () => {
      it('should be created and destroyed', injectAsync([], () => {
        return setup().then((api: ITestFixture) => api.fixture.destroy());
      }));
      it('should be registered and unregistered with SidenavService', injectAsync([], () => {
        expect(service.find('test')).toBeNull();
        return setup(`<md-sidenav name="test"></md-sidenav>`).then((api: ITestFixture) => {
          expect(service.find('test')).not.toBeNull();
          api.fixture.destroy();
          expect(service.find('test')).toBeNull();
        });
      }));
      describe('name', () => {
        it('should default to "default"', injectAsync([], () => {
          return setup().then((api: ITestFixture) => {
            expect(api.component.name).toBe('default');
          });
        }));
      });

      describe('style', () => {
        it('should default to over', injectAsync([], () => {
          return setup().then((api: ITestFixture) => {
            expect(api.component.style).toBe(SidenavStyle.OVER);
          });
        }));
        it('should set to default when given an invalid value', injectAsync([], () => {
          return setup(`<md-sidenav style="gangnam"></md-sidenav>`).then((api: ITestFixture) => {
            expect(api.component.style).toBe(SidenavStyle.OVER);
          });
        }));
        it('should accept "side" for content pushing', injectAsync([], () => {
          return setup(`<md-sidenav style="side"></md-sidenav>`).then((api: ITestFixture) => {
            expect(api.component.style).toBe(SidenavStyle.SIDE);
          });
        }));
      });

      describe('align', () => {
        it('should default to "left"', injectAsync([], () => {
          return setup().then((api: ITestFixture) => {
            expect(api.component.align).toBe(SidenavAlignment.LEFT);
          });
        }));
        it('should set to default when given an invalid value', injectAsync([], () => {
          return setup(`<md-sidenav align="up"></md-sidenav>`).then((api: ITestFixture) => {
            expect(api.component.align).toBe(SidenavAlignment.LEFT);
          });
        }));
        it('should accept "side" for content pushing', injectAsync([], () => {
          return setup(`<md-sidenav align="right"></md-sidenav>`).then((api: ITestFixture) => {
            expect(api.component.align).toBe(SidenavAlignment.RIGHT);
          });
        }));

      });
    });
    describe('md-sidenav-container', () => {
      let template = `
      <md-sidenav-container>
        <md-sidenav name="menu"></md-sidenav>
        <md-sidenav name="right" align="right"></md-sidenav>
      </md-sidenav-container>`;
      it('should be created and destroyed', injectAsync([], () => {
        return setup(template).then((api: ITestFixture) => {
          api.fixture.destroy();
        });
      }));
      it('should maintain a query list of its children', injectAsync([], () => {
        return setup(template).then((api: ITestFixture) => {
          expect(api.container.children.length).toBe(2);
          api.fixture.destroy();
        });
//.........这里部分代码省略.........
开发者ID:dmacfarlane,项目名称:ng2-material,代码行数:101,代码来源:sidenav_spec.ts


示例3: it

 it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
   return tcb.createAsync(PantalonesComponent).then((fixture: ComponentFixture) => {
     fixture.detectChanges();
   });
 }));
开发者ID:andresciceri,项目名称:catalogo-angular-2,代码行数:5,代码来源:pantalones.component.spec.ts


示例4: describe

  describe('MdLiveAnnouncer', () => {
    let live: MdLiveAnnouncer;
    let builder: TestComponentBuilder;
    let liveEl: Element;

    beforeEachProviders(() => [MdLiveAnnouncer]);

    beforeEach(inject([TestComponentBuilder, MdLiveAnnouncer],
      (tcb: TestComponentBuilder, _live: MdLiveAnnouncer) => {
        builder = tcb;
        live = _live;
        liveEl = getLiveElement();
    }));

    afterEach(() => {
      // In our tests we always remove the current live element, because otherwise we would have
      // multiple live elements due multiple service instantiations.
      liveEl.parentNode.removeChild(liveEl);
    });

    it('should correctly update the announce text', fakeAsyncTest(() => {
      let appFixture: ComponentFixture = null;

      builder.createAsync(TestApp).then(fixture => {
        appFixture = fixture;
      });

      flushMicrotasks();

      let buttonElement = appFixture.debugElement
        .query(By.css('button')).nativeElement;

      buttonElement.click();

      // This flushes our 100ms timeout for the screenreaders.
      tick(100);

      expect(liveEl.textContent).toBe('Test');
    }));

    it('should correctly update the politeness attribute', fakeAsyncTest(() => {
      let appFixture: ComponentFixture = null;

      builder.createAsync(TestApp).then(fixture => {
        appFixture = fixture;
      });

      flushMicrotasks();

      live.announce('Hey Google', 'assertive');

      // This flushes our 100ms timeout for the screenreaders.
      tick(100);

      expect(liveEl.textContent).toBe('Hey Google');
      expect(liveEl.getAttribute('aria-live')).toBe('assertive');
    }));

    it('should apply the aria-live value polite by default', fakeAsyncTest(() => {
      let appFixture: ComponentFixture = null;

      builder.createAsync(TestApp).then(fixture => {
        appFixture = fixture;
      });

      flushMicrotasks();

      live.announce('Hey Google');

      // This flushes our 100ms timeout for the screenreaders.
      tick(100);

      expect(liveEl.textContent).toBe('Hey Google');
      expect(liveEl.getAttribute('aria-live')).toBe('polite');
    }));

  });
开发者ID:AlmeroSteyn,项目名称:material2,代码行数:77,代码来源:live-announcer.spec.ts


示例5: describe

  describe('MdRadioButton', () => {
    let builder: TestComponentBuilder;

    beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
      builder = tcb;
    }));

    it('should have same name as radio group', (done: () => void) => {
      builder
        .overrideTemplate(TestApp, `
            <md-radio-group name="my_group">
              <md-radio-button></md-radio-button>
            </md-radio-group>`)
        .createAsync(TestApp)
        .then((fixture) => {
          let button = fixture.debugElement.query(By.css('md-radio-button'));

          fixture.detectChanges();
          expect(button.componentInstance.name).toBe('my_group');
        }).then(done);
    });

    it('should not allow click selection if disabled', (done: () => void) => {
      builder
        .overrideTemplate(TestApp, '<md-radio-button disabled></md-radio-button>')
        .createAsync(TestApp)
        .then((fixture) => {
          let button = fixture.debugElement.query(By.css('md-radio-button'));

          fixture.detectChanges();
          expect(button.componentInstance.checked).toBe(false);

          button.nativeElement.click();
          expect(button.componentInstance.checked).toBe(false);
        }).then(done);
    });

    it('should be disabled if radio group disabled', (done: () => void) => {
      builder
        .overrideTemplate(TestApp, `
            <md-radio-group disabled>
              <md-radio-button></md-radio-button>
            </md-radio-group>`)
        .createAsync(TestApp)
        .then((fixture) => {
          let button = fixture.debugElement.query(By.css('md-radio-button'));

          fixture.detectChanges();
          expect(button.componentInstance.disabled).toBe(true);
        }).then(done);
    });

    it('updates parent group value when selected and value changed', (done: () => void) => {
      builder
        .overrideTemplate(TestApp, `
            <md-radio-group>
              <md-radio-button value="1"></md-radio-button>
            </md-radio-group>`)
        .createAsync(TestApp)
        .then((fixture) => {
          let button = fixture.debugElement.query(By.css('md-radio-button'));
          let group = fixture.debugElement.query(By.css('md-radio-group'));

          group.componentInstance.selected = button.componentInstance;
          fixture.detectChanges();
          expect(group.componentInstance.value).toBe('1');

          button.componentInstance.value = '2';
          fixture.detectChanges();
          expect(group.componentInstance.value).toBe('2');
        }).then(done);
    });

    it('should be checked after input change event', (done: () => void) => {
      builder
        .overrideTemplate(TestApp, '<md-radio-button></md-radio-button>')
        .createAsync(TestApp)
        .then((fixture) => {
          let button = fixture.debugElement.query(By.css('md-radio-button'));
          let input = button.query(By.css('input'));

          fixture.detectChanges();
          expect(button.componentInstance.checked).toBe(false);

          let event = createEvent('change');
          input.nativeElement.dispatchEvent(event);
          expect(button.componentInstance.checked).toBe(true);
        }).then(done);
    });

    it('should emit event when checked', (done: () => void) => {
      builder
        .overrideTemplate(TestApp, '<md-radio-button></md-radio-button>')
        .createAsync(TestApp)
        .then((fixture) => {
          fakeAsync(function() {
            let button = fixture.debugElement.query(By.css('md-radio-button'));
            let changeEvent: MdRadioChange = null;
            button.componentInstance.change.subscribe((evt: MdRadioChange) => {
              changeEvent = evt;
//.........这里部分代码省略.........
开发者ID:tkhemani,项目名称:a2MaterialAlpha,代码行数:101,代码来源:radio_button.spec.ts


示例6:

const compile = (tcb: TestComponentBuilder, template: string = '') => {
  return tcb
    .overrideTemplate(TestComponent, template)
    .createAsync(TestComponent);
};
开发者ID:jennyraj,项目名称:router,代码行数:5,代码来源:link-to.spec.ts


示例7: it

 it('should ...', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
   return tcb.createAsync(ChildComponent).then((fixture: ComponentFixture) => {
     fixture.detectChanges();
   });
 })));
开发者ID:Brocco,项目名称:route-issue,代码行数:5,代码来源:child.component.spec.ts


示例8: it

 it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
   return tcb.createAsync(MouridismeText).then((fixture) => {
     fixture.detectChanges();
   });
 }));
开发者ID:wadendo,项目名称:angular2-app,代码行数:5,代码来源:mouridisme-text.spec.ts


示例9: compile

export function compile(tcb: TestComponentBuilder): Promise<ComponentFixture> {
  return tcb.createAsync(RootCmp);
}
开发者ID:jamescarter-le,项目名称:angulartics2,代码行数:3,代码来源:test.mocks.ts


示例10: it

    it('should select uniquely', (done: () => void) => {
      builder
        .overrideTemplate(TestApp, `
            <md-radio-group>
              <md-radio-button></md-radio-button>
              <md-radio-button></md-radio-button>
            </md-radio-group>`)
        .createAsync(TestApp)
        .then((fixture) => {
          let buttons = fixture.debugElement.queryAll(By.css('md-radio-button'));
          let group = fixture.debugElement.query(By.css('md-radio-group'));

          fixture.detectChanges();
          expect(group.componentInstance.selected).toBe(null);

          group.componentInstance.selected = buttons[0].componentInstance;
          fixture.detectChanges();
          expect(isSinglySelected(buttons[0], buttons)).toBe(true);

          group.componentInstance.selected = buttons[1].componentInstance;
          fixture.detectChanges();
          expect(isSinglySelected(buttons[1], buttons)).toBe(true);
        }).then(done);
    });
开发者ID:LuanNg,项目名称:material2,代码行数:24,代码来源:radio.spec.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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