TypeScript @angular-compiler-testing.TestComponentBuilder类(方法)实例源码

下面列出了TypeScript @angular-compiler-testing.TestComponentBuilder 类(方法)源码代码实例,从而了解它的用法。

作者:stevenkampe    项目:ng2-sequence   
describe('Component: Button', () => {
  let builder: TestComponentBuilder;

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

  it('should invoke onClick when clicked',
    async(inject([], () => {
      return builder.createAsync(SoundBlip)
        .then((fixture: ComponentFixture<any>) => {
          spyOn(fixture.componentInstance, 'onClick');
          fixture.componentInstance.qaid = 'button-1';
          fixture.detectChanges();
          let compiled = fixture.debugElement.nativeElement;
          compiled.querySelector('#button-1').click();
          expect(fixture.componentInstance.handleClick).toHaveBeenCalled();
        });
    }))
  );
});

作者:4vange    项目:angula   
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
               var template = '<div>' +
                   '<ul [ngSwitch]="switchValue">' +
                   '<template ngSwitchWhen="a"><li>when a</li></template>' +
                   '<template ngSwitchWhen="b"><li>when b</li></template>' +
                   '</ul></div>';

               tcb.overrideTemplate(TestComponent, template)
                   .createAsync(TestComponent)
                   .then((fixture) => {
                     fixture.detectChanges();
                     expect(fixture.debugElement.nativeElement).toHaveText('');

                     fixture.debugElement.componentInstance.switchValue = 'a';
                     fixture.detectChanges();
                     expect(fixture.debugElement.nativeElement).toHaveText('when a');

                     fixture.debugElement.componentInstance.switchValue = 'b';
                     fixture.detectChanges();
                     expect(fixture.debugElement.nativeElement).toHaveText('when b');

                     async.done();
                   });
             }));

作者:gitter-badge    项目:covalen   
describe('Component: Home', () => {
  let builder: TestComponentBuilder;

  beforeEachProviders(() => [
    HomeComponent,
    TD_LAYOUT_PROVIDERS,
  ]);
  beforeEach(inject([TestComponentBuilder], function (tcb: TestComponentBuilder): void {
    builder = tcb;
  }));

  it('should inject the component', inject([HomeComponent], (component: HomeComponent) => {
    expect(component).toBeTruthy();
  }));

  it('should create the component', inject([], () => {
    return builder.createAsync(HomeTestControllerComponent)
      .then((fixture: ComponentFixture<any>) => {
        let query: DebugElement = fixture.debugElement.query(By.directive(HomeComponent));
        expect(query).toBeTruthy();
        expect(query.componentInstance).toBeTruthy();
      });
  }));
});

作者:aftab1066    项目:angula   
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: any /** TODO #9100 */) => {
           var html = '<div><copy-me template="ngIf numberCondition">hello</copy-me></div>';

           tcb.overrideTemplate(TestComponent, html)
               .createAsync(TestComponent)
               .then((fixture) => {
                 fixture.detectChanges();
                 expect(getDOM()
                            .querySelectorAll(fixture.debugElement.nativeElement, 'copy-me')
                            .length)
                     .toEqual(1);
                 expect(fixture.debugElement.nativeElement).toHaveText('hello');

                 fixture.debugElement.componentInstance.numberCondition = 2;
                 fixture.detectChanges();
                 expect(getDOM()
                            .querySelectorAll(fixture.debugElement.nativeElement, 'copy-me')
                            .length)
                     .toEqual(1);
                 expect(fixture.debugElement.nativeElement).toHaveText('hello');

                 async.done();
               });
         }));

作者:aftab1066    项目:angula   
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: any /** TODO #9100 */) => {
         var template = `<div [ngStyle]="expr"></div>`;

         tcb.overrideTemplate(TestComponent, template)
             .createAsync(TestComponent)
             .then((fixture) => {
               var expr: Map<string, any>;

               fixture.debugElement.componentInstance.expr = {'max-width': '40px'};
               fixture.detectChanges();
               expect(
                   getDOM().getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
                   .toEqual('40px');

               expr = fixture.debugElement.componentInstance.expr;
               (expr as any /** TODO #9100 */)['max-width'] = '30%';
               fixture.detectChanges();
               expect(
                   getDOM().getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
                   .toEqual('30%');

               async.done();
             });
       }));

作者:IDEXXIH    项目:angulartics   
(tcb: TestComponentBuilder, location: Location, angulartics2: Angulartics2, angulartics2Piwik: Angulartics2Piwik) => {
		  fixture = tcb.createFakeAsync(RootCmp);
		  angulartics2.setUserProperties.next({ userId: '1', firstName: 'John', lastName: 'Doe' });
		  advance(fixture);
		  expect(_paq).toContain(['setCustomVariable', { userId: '1', firstName: 'John', lastName: 'Doe' }]);
		})));

作者:CoderMonkie    项目:route   
const compile = (tcb: TestComponentBuilder, template: string = '') => {
  return tcb
    .overrideTemplate(TestComponent, template)
    .createAsync(TestComponent);
};


问题


面经


文章

微信
公众号

扫码关注公众号