當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript testing.injectAsync函數代碼示例

本文整理匯總了TypeScript中angular2/testing.injectAsync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript injectAsync函數的具體用法?TypeScript injectAsync怎麽用?TypeScript injectAsync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了injectAsync函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

describe('When loading the UserAppComponent', () => {
  
  var mockRouterProvider: MockRouterProvider = new MockRouterProvider();
  
  beforeEachProviders(() => {
    return [mockRouterProvider.getProviders()];
  });
  
  it('should do something', 
    injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
      return tcb
        .createAsync(UserAppComponent)
        .then((fixture: ComponentFixture) => {
          fixture.detectChanges();
          let compiled = fixture.debugElement.nativeElement;
        });
    })
  );
  
});
開發者ID:aneagoie,項目名稱:angular2-unit-test-app,代碼行數:20,代碼來源:user-app.component.spec.ts

示例2: 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', injectAsync([TestComponentBuilder],
        (tsb: TestComponentBuilder) => {
            return 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:Darkniel,項目名稱:angular2-zitio,代碼行數:20,代碼來源:app.component.spec.ts

示例3: describe

describe('App', () => {
  let fixture: ComponentFixture;

  beforeEach(injectAsync([TestComponentBuilder], tcb => {
    return tcb.createAsync(App)
      .then(f => fixture = f);
  }));

  it('should have a title', () => {
    // given a component instance
    let appCmp = fixture.componentInstance;

    // when we trigger the change detection
    fixture.detectChanges();

    // then we should have a name
    let element = fixture.nativeElement;
    expect(element.querySelector('h1')).toHaveText('Hello, Angular2!');
  });
});
開發者ID:gdangelo,項目名稱:angular2-starter,代碼行數:20,代碼來源:app.spec.ts

示例4: describe

describe('Testing Login Component Failed Flow', () => {
  let mockRouterProvider = new MockRouterProvider();

  beforeEachProviders(() => {
    return [
      provide(AuthService, {useClass: MockFailedAuthService}),
      mockRouterProvider.getProviders(),
      FormBuilder
    ];
  });

  it('Login should fail', injectAsync([TestComponentBuilder],
      (tcb: TestComponentBuilder) => {
    return tcb.createAsync(LoginComponent).then(fixture => {
      const instance = fixture.debugElement.componentInstance;
      instance.login();
      chai.expect(instance.message).to.equal('Incorrect credentials.');
    });
  }));
});
開發者ID:ManuCutillas,項目名稱:ngCourse2,代碼行數:20,代碼來源:login.spec.ts

示例5: describe

describe('DashboardComponent',  () => {
  beforeEachProviders(() => [
    provide(Router, { useValue: {} }),
    provide(SpeakerService, {
      useValue: {
        getSpeakers: () => { },
        onDbReset: () => { }
    }}),
    ToastService
  ]);

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

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

});
開發者ID:nickbarnettworks,項目名稱:event-view,代碼行數:20,代碼來源:dashboard.component.spec.ts

示例6: describe

describe('Search Tests', () => {

  beforeEachProviders(() => [
    HTTP_PROVIDERS,
    provide(MainService, { useClass: MockMainService })
  ]);

  it('should change if active', injectAsync([TestComponentBuilder], (tcb) => {
    return tcb
      .overrideProviders(
        Search, [provide(MainService, { useClass: MockMainService })]
      )
      .createAsync(Search).then((fixture) => {
        fixture.componentInstance.search('url');
        fixture.detectChanges();
        let compiled = fixture.debugElement.nativeElement;
        expect(compiled.outerHTML).toContain('TTT');
      });
  }));

});
開發者ID:astagi,項目名稱:angular2-workbench,代碼行數:21,代碼來源:search.spec.ts

示例7: describe

  describe('App component', () => {

    // Support for testing component that uses Router
    beforeEachProviders(() => [
      RouteRegistry,
      DirectiveResolver,
      provide(Location, {useClass: SpyLocation}),
      provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppComponent}),
      provide(Router, {useClass: RootRouter})
    ]);

    it('should work',
      injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
        return tcb.createAsync(TestComponent)
          .then(rootTC => {
            rootTC.detectChanges();
            let appDOMEl = rootTC.debugElement.children[0].nativeElement;
            expect(DOM.querySelectorAll(appDOMEl, 'c-app > c-navbar > nav > a')[1].href).toMatch(/http:\/\/localhost:\d+\/about/);
          });
      }));
  });
開發者ID:unit9,項目名稱:gae-secure-scaffold-python,代碼行數:21,代碼來源:c-app.spec.ts

示例8: describe

describe('SampleComponent', () => {
  let fixture;
  
  //setup
  beforeEachProviders(() => [
    TestComponentBuilder
  ]);

  beforeEach(injectAsync([TestComponentBuilder], tcb => {
    return tcb
      .createAsync(TestComponent)
      .then(f => fixture = f);
  }));

  it('should say something about making a library', () => {
    let container = fixture.componentInstance,
      div = fixture.nativeElement.querySelector('div');
    expect(div.textContent).toBe('');
  });

});
開發者ID:jesperronn,項目名稱:angular2-library-seed,代碼行數:21,代碼來源:sample.component.spec.ts

示例9: describe

describe('SanitizeDirective', () => {
  let fixture;
  
  //setup
  beforeEachProviders(() => [
    TestComponentBuilder
  ]);

  beforeEach(injectAsync([TestComponentBuilder], tcb => {
    return tcb
      .createAsync(TestComponent)
      .then(f => fixture = f);
  }));

  it('should add a class', () => {
    let container = fixture.componentInstance,
      div = fixture.nativeElement.querySelector('div');
    expect(div.getAttribute('class')).toBe('sample-class');
  });

});
開發者ID:NathanWalker,項目名稱:ng2-sanitize,代碼行數:21,代碼來源:sanitize.directive.spec.ts

示例10: describe

describe('AppComponent', () => {

    beforeEachProviders(() => [
        AppComponent
    ]);

    it('should exist', inject([AppComponent], (appComponent:AppComponent) => {
        expect(appComponent).toBeDefined();
    }));

    it('should render a header', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
        return tcb.createAsync(AppComponent)
            .then((fixture:ComponentFixture) => {
                let element = fixture.nativeElement;
                let appComponent = fixture.componentInstance;
                fixture.detectChanges();
                expect(element.querySelectorAll('h1').length).toBe(1);
            });
    }));
    
});
開發者ID:Georg-W,項目名稱:angular2-tdd-boilerplate,代碼行數:21,代碼來源:app.component.spec.ts


注:本文中的angular2/testing.injectAsync函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。