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


TypeScript testing.async函数代码示例

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


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

示例1: describe

describe('AppComponent with TCB', function () {

  it('should instantiate component',
    async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {

    tcb.createAsync(AppComponent).then(fixture => {
      expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
    });
  })));

  it('should have expected <h1> text',
    async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {

      tcb.createAsync(AppComponent).then(fixture => {
      // fixture.detectChanges();  // would need to resolve a binding but we don't have a binding

      let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement;  // it works

          h1 = fixture.debugElement.query(By.css('h1')).nativeElement;            // preferred

      expect(h1.innerText).toMatch(/angular 2 app/i, '<h1> should say something about "Angular 2 App"');
    });

  })));
});
开发者ID:2blessed2bstressedbythedevilsmess,项目名称:quickstart,代码行数:25,代码来源:app.component.spec.ts

示例2: describe

describe('TodolistComponent', () => {
    it('should have been created successfully', async(inject([TestComponentBuilder],
        (tcb: TestComponentBuilder) => {
            tcb.createAsync(TestComponent).then((fixture) => {
                testFixture = fixture;
                fixture.detectChanges();

                todoCompiled = fixture.nativeElement;
                todolistCmp = fixture.debugElement
                    .children[0].componentInstance;
                expect(todoCompiled).toBeDefined();
            });
    })));

    it('should add todo successfully', () => {
        todolistCmp.todo = new Todo('test', true);
        todolistCmp.addTodo();
        testFixture.detectChanges();

        let items = todoCompiled.querySelectorAll('.list-group-item');
        expect(items.length).toEqual(3);

        let item = items[items.length - 1];
        expect(item.querySelector('label').textContent).toEqual(' test');
        expect(item.querySelector('input[type="checkbox"]').checked).toBeTruthy();
    });

    it('should delete todo successfully', () => {
        todolistCmp.delTodo(0);
        testFixture.detectChanges();
        expect(todoCompiled.querySelectorAll('.list-group-item').length)
            .toEqual(2);
    });
});
开发者ID:leoalmeida,项目名称:petitfour,代码行数:34,代码来源:todolist.component.spec.ts

示例3: describe

describe('ChildComponent', () => {
    it('should print inputs correctly', async(inject([TestComponentBuilder],
    (tsb: TestComponentBuilder) => {
        tsb.createAsync(TestComponent).then((fixture) => {
            testFixture = fixture;
            testFixture.detectChanges();

            childCompiled = testFixture.nativeElement;
            childCmp = testFixture.debugElement.children[0].componentInstance;

            expect(childCompiled).toBeDefined();
            expect(childCmp).toBeDefined();
            expect(childCompiled.querySelector('h6'))
                .toHaveText('From parent');
            expect(childCompiled.querySelector('h5'))
                .toHaveText('Hello test');
        });
    })));

    it('should trigger changeMe event correctly', () => {
        childCmp.changeMe();
        testFixture.detectChanges();
        expect(childCmp.num).toEqual(1);
        expect(childCompiled.querySelector('h6'))
            .toHaveText('Changed from child. Count: ' + childCmp.num);
    });
});
开发者ID:leoalmeida,项目名称:petitfour,代码行数:27,代码来源:child.component.spec.ts

示例4: describe

describe('About Component', () => {

  beforeEachProviders(() => []);

  it('should ...', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
    tcb.createAsync(About).then((fixture) => {
      fixture.detectChanges();
    });
  })));

});
开发者ID:Cammisuli,项目名称:angular2-animation-test,代码行数:11,代码来源:about.spec.ts

示例5: describe

describe('LoggedInOutlet Directive', () => {

  beforeEachProviders(() => []);


  it('should ...', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
    tcb.createAsync(TestComponent).then((fixture) => {
      fixture.detectChanges();
    });
  })));

});
开发者ID:BrooklynLabs,项目名称:angular2-webpack-login,代码行数:12,代码来源:logged-in-outlet.spec.ts

示例6: describe

describe('SimplebindComponent', () => {
    it('should have print "Simple" on template', async(inject([TestComponentBuilder],
    (tsb: TestComponentBuilder) => {
        tsb.createAsync(TestComponent).then((fixture) => {
            fixture.detectChanges();
            let compiled = fixture.debugElement.nativeElement;
            expect(compiled).toBeDefined();
            expect(compiled.querySelector('p'))
                .toHaveText('Simple');
        });
    })));
});
开发者ID:leoalmeida,项目名称:petitfour,代码行数:12,代码来源:simplebind.component.spec.ts

示例7: describe

describe('Child Component', () => {

  beforeEachProviders(() => [
    provide(Router, { useClass: MockRouter }),
    provide(RouteParams, { useClass: MockRouteParams }),
  ]);

  it('should ...', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
    return tcb.createAsync(ChildComponent).then((fixture: ComponentFixture) => {
      fixture.detectChanges();
    });
  })));

});
开发者ID:Brocco,项目名称:route-issue,代码行数:14,代码来源:child.component.spec.ts

示例8: describe

  describe('With Hash', () => {
    it('should add the provided class to the active element', async(inject([TestComponentBuilder, Router, LocationStrategy], (tcb, router$, ls) => {
      ls.internalBaseHref = '#';

      router$.next({
        path: '/'
      });

      return compile(tcb, '<a linkActive="active" linkTo="/">Page</a>')
        .then((fixture) => {
          fixture.detectChanges();
          let compiled = fixture.debugElement.nativeElement;
          let link: Element = compiled.querySelector('a');

          expect(link.getAttribute('class')).toEqual('active');
        });
    })));
  });
开发者ID:MikeRyan52,项目名称:router,代码行数:18,代码来源:link-active.spec.ts

示例9: describe

describe('x-large directive', () => {
  // Create a test component to test directives
  @Component({
    template: '',
    directives: [ XLarge ]
  })
  class TestComponent {}

  it('should sent font-size to x-large', async(inject([TestComponentBuilder], (tcb) => {
    return tcb.overrideTemplate(TestComponent, '<div x-large>Content</div>')
      .createAsync(TestComponent).then((fixture: any) => {
        fixture.detectChanges();
        let compiled = fixture.debugElement.nativeElement.children[0];
        expect(compiled.style.fontSize).toBe('x-large');
      });
  })));

});
开发者ID:Augustin82,项目名称:angular2-webpack-starter,代码行数:18,代码来源:x-large.spec.ts

示例10: describe

describe('AppComponent', () => {
    beforeEachProviders(() => [
        LoggerService,
        ROUTER_PROVIDERS,
        provide(ROUTER_PRIMARY_COMPONENT, { useValue: AppComponent }),
        provide(ApplicationRef, { useClass: MockApplicationRef }),
        provide(APP_BASE_HREF, { useValue: '/' }),
    ]);

    it('should have brand Angular 2 Starter', async(inject([TestComponentBuilder],
        (tsb: TestComponentBuilder) => {
            tsb.createAsync(TestComponent).then((fixture) => {
                fixture.detectChanges();
                let compiled = fixture.debugElement.nativeElement;
                expect(compiled).toBeDefined();
                expect(compiled.querySelector('a.navbar-brand'))
                    .toHaveText('Angular 2 Starter');
            });
        })));
});
开发者ID:leoalmeida,项目名称:petitfour,代码行数:20,代码来源:app.component.spec.ts


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