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

TypeScript mocha.beforeEach函数代码示例

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

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



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

示例1: describe

describe("AboutComponent", () => {

  beforeEachProviders(() => [
    MockBackend,
    BaseRequestOptions,
    provide(Http, {
      useFactory: (backend: MockBackend, options: BaseRequestOptions) => new Http(backend, options),
      deps: [MockBackend, BaseRequestOptions]
    })
  ]);

  let builder: TestComponentBuilder;
  beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
    builder = tcb
      .overrideTemplate(AboutComponent, require("./about.html"));
  }));

  it("can create", async(
    inject([], () => {
      builder.createAsync(AboutComponent);
    }))
  );

  it("has expected view", async(
    inject([], () => {
      builder
        .createAsync(AboutComponent)
        .then(fixture => {
          assert.equal(fixture.debugElement.nativeElement.innerHTML, `<h3>About Component</h3>
<p>This is the about component!</p>`);
        });
    }))
  );
});
开发者ID:laco0416,项目名称:angular2-seed,代码行数:34,代码来源:about.spec.ts


示例2: describe

describe("HomeComponent", () => {

  beforeEachProviders(() => [
  ]);

  let builder: TestComponentBuilder;
  beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
    builder = tcb
      .overrideTemplate(HomeComponent, require("./home.html"));
  }));

  it("can create", async(
    inject([], () => {
      builder.createAsync(HomeComponent);
    }))
  );

  it("has expected view", async(
    inject([], () => {
      builder
        .createAsync(HomeComponent)
        .then(fixture => {
          assert.equal(fixture.debugElement.nativeElement.innerHTML, `<h3>Home Component</h3>
<p>Welcome to Angular Seed</p>`);
        });
    }))
  );
});
开发者ID:laco0416,项目名称:angular2-seed,代码行数:28,代码来源:home.spec.ts


示例3: describe

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

  beforeEachProviders(() => [KelvinToCelsiusPipe]);

  beforeEach(inject([ TestComponentBuilder ], (tcb: TestComponentBuilder) => {
    builder = tcb.overrideProviders(
      WeatherWidget,
      [ provide(OpenWeatherApi, { useClass : MockOpenWeatherApi }) ]);
  }));

  it('can create', () => {
    return builder.createAsync(WeatherWidget).then(fixture => {
      expect(fixture).to.exist;
    });
  });

  it('should display the city name', () => {
    return builder.createAsync(WeatherWidget).then(fixture => {
      let component = fixture.componentInstance,
          element = fixture.nativeElement;

      component.city = 'Berlin';

      fixture.detectChanges();
      expect(element.querySelector('.weather__city').innerText)
        .to.equal('Berlin');
    });
  });

  it('should transform the temperature from Kelvin to Celcius and display it',
     () => {
       return builder.createAsync(WeatherWidget).then(fixture => {
         let component = fixture.componentInstance,
             element = fixture.nativeElement;

         component.city = 'Berlin';

         fixture.detectChanges();
         expect(element.querySelector('.weather__detail__temp').innerText)
           .to.equal('21.91°C');
       });
     });

  it('should contain an icon with a url by open weather api', () => {
    return builder.createAsync(WeatherWidget).then(fixture => {
      let component = fixture.componentInstance,
          element = fixture.nativeElement;

      component.city = 'Berlin';

      fixture.detectChanges();
      expect(element.querySelector('img').getAttribute('src'))
        .to.equal('http://openweathermap.org/img/w/01d.png');
      expect(component.generateIconUrl())
        .to.equal('http://openweathermap.org/img/w/01d.png');
    });
  });
});
开发者ID:luhmann,项目名称:ng2-webpack-weather-widget,代码行数:59,代码来源:weather-widget.component.spec.ts


示例4: xdescribe

xdescribe('Component: App', () => {
  let builder: TestComponentBuilder;

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

  it('can create', () => {
    builder.createAsync(AppComponent).then(fixture => {
      expect(fixture).to.exist;
    });
  });
});
开发者ID:luhmann,项目名称:ng2-webpack-weather-widget,代码行数:13,代码来源:app.component.spec.ts


示例5: xdescribe

  xdescribe('getWeatherForCity', () => {
    beforeEach(inject([ MockBackend ], (backend: MockBackend) => {
      backend.connections.subscribe((c: MockConnection) => {
        c.mockRespond(new Response(
          new ResponseOptions({ status : 200, body : { 'city' : 'Berlin' } })));
      });
    }));

    it('should return the mock data',
       async(inject([ OpenWeatherApi ], (service: OpenWeatherApi) => {
         service.getWeatherForCity('Berlin').toPromise().then(
           resp => { expect(resp).to.exist; });
       })));
  });
开发者ID:luhmann,项目名称:ng2-webpack-weather-widget,代码行数:14,代码来源:open-weather-api.service.spec.ts


示例6: describe

describe("AppRootComponent", () => {

  beforeEachProviders(() => [
    ...ROUTER_FAKE_PROVIDERS
  ]);

  let builder: TestComponentBuilder;
  beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
    builder = tcb
      .overrideTemplate(AppRootComponent, require("./app-root.html"));
  }));

  it("can create", async(
    inject([], () => {
      builder.createAsync(AppRootComponent);
    }))
  );
});
开发者ID:laco0416,项目名称:angular2-seed,代码行数:18,代码来源:app-root.spec.ts


示例7: describe

describe("RepoBrowserComponent", () => {

  beforeEachProviders(() => [
    ...ROUTER_FAKE_PROVIDERS,
  ]);

  let builder: TestComponentBuilder;
  beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
    builder = tcb
      .overrideTemplate(RepoBrowserComponent, require("./repo-browser.html"))
      .overrideProviders(RepoBrowserComponent, [
        provide(GitHub, {useClass: MockGitHub})
      ]);
  }));

  it("can create", async(
    () => {
      builder.createAsync(RepoBrowserComponent);
    })
  );
});
开发者ID:laco0416,项目名称:angular2-seed,代码行数:21,代码来源:repo-browser.spec.ts


示例8: describe

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

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

  it("can create", async(() => {
    builder.createAsync(AppComponent)
      .then(fixture => {
        assert(!!fixture);
      });
  }));

  it("should has text: 'My First Angular 2 App'", async(() => {
    builder.createAsync(AppComponent)
      .then(fixture => {
        let el = fixture.debugElement;
        assert(el.query(By.css("h1")).nativeElement.innerHTML === "My First Angular 2 App");
      });
  }));

  it("should has text: 'My Test'", async(() => {
    builder.createAsync(AppComponent)
      .then(fixture => {
        let el = fixture.debugElement;
        assert(el.query(By.css("p")).nativeElement.innerHTML === "My Test");
      });
  }));

  it("should fail", async(() => {
    let app = new AppComponent();
    let num = app.getNumber();
    assert(num === 101);
  }));
});
开发者ID:ovrmrw,项目名称:angular2-testing-lite-5min-sample,代码行数:36,代码来源:app.spec.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript mocha.beforeEachProviders函数代码示例发布时间:2022-05-28
下一篇:
TypeScript core.TestComponentBuilder类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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