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


TypeScript Sinon.SinonFakeServer类代码示例

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


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

示例1: describe

describe('weather services', () => {
  let service: WeatherMapService;
  let server: SinonFakeServer;

  const MockStations = require('mocks/stations.json');
  const MockForecasts = require('mocks/forecast01.json');
  const lat = 1;
  const lon = 1;

  beforeEach(() => {
    server = fakeServer.create();
    server.respondWith(
      'GET',
      OWM_API_STATION(),
      fakeResponse(200, MockStations)
    );
    server.respondWith(
      'GET',
      OWM_API_FORECAST(lat, lon),
      fakeResponse(200, MockForecasts)
    );
    server.respondImmediately = true;
  });

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [ HttpModule ],
      providers: [
        WeatherMapService
      ]
    });
  });

  beforeEach(inject([WeatherMapService], (weatherMapService: WeatherMapService) => {
    service = weatherMapService;
  }));

  afterEach(() => {
    TestBed.resetTestingModule();
    server.restore();
  });

  it('getStations should be a stations observable and having a Map Immutable response', done => {
    const MockStationMap = generateMap(MockStations.list, StationModel);
    service.getStations()
    .subscribe(result => {
      expect(result).to.deep.equal(MockStationMap);
      done();
    });
  });

  it('getForecast should be a forecasts observable and having a Map Immutable response', done => {
    const MockForecastsMap = generateMap(MockForecasts.list, ForecastModel);
    const getForecast = service.getForecast(lat, lon);
    expect(getForecast).to.be.instanceof(Observable);

    getForecast.subscribe(result => {
      expect(result).to.deep.equal(MockForecastsMap);
      done();
    });
  });
});
开发者ID:atSistemas,项目名称:angular-base,代码行数:62,代码来源:weather-map.service.spec.ts

示例2: describe

describe('Integration tests in Weather Container', () => {
  let container: WeatherContainer;
  let mapComponent: MapComponent;
  let fixture: ComponentFixture<WeatherContainer>;
  let de: DebugElement;
  let deMap: DebugElement;
  let el: HTMLElement;
  let server: SinonFakeServer;

  const MockStations = require('mocks/stations.json');
  const MockForecast01 = require('mocks/forecast01.json');
  const MockForecast02 = require('mocks/forecast02.json');

  beforeEach(() => {
    server = fakeServer.create();
    server.respondWith(
      'GET',
      OWM_API_STATION(),
      fakeResponse(200, MockStations)
    );
    server.respondWith(
      'GET',
      OWM_API_FORECAST(1, 1),
      fakeResponse(200, MockForecast01)
    );
    server.respondWith(
      'GET',
      OWM_API_FORECAST(2, 2),
      fakeResponse(200, MockForecast02)
    );
    server.respondImmediately = true;
  });

  beforeEach((done) => {
    TestBed.configureTestingModule({
      imports: [
        HttpModule,
        GoogleMapsModule,
        StoreModuleImport,
        EffectsModuleImport
      ],
      declarations: [
        WeatherContainer,
        MapComponent,
        ForecastComponent,
        StationInfoComponent,
        StationMarkerComponent,
        ForecastDetailComponent,
        HumidityPipe,
        PressurePipe,
        TemperaturePipe
      ],
      providers: [
        RequestEffect,
        WeatherActions,
        WeatherMapService
      ]
    })
    .compileComponents()
    .then(done);
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(WeatherContainer);
    fixture.detectChanges();
    container = fixture.componentInstance;

    de = fixture.debugElement;
    el = de.nativeElement;

    deMap = de.query(By.css('weather-map'));
    mapComponent = deMap.componentInstance;
  });

  afterEach(() => {
    container.ngOnDestroy();
    TestBed.resetTestingModule();
    server.restore();
  });

  describe('Layout', () => {
    it('should render 3 mock stations', done => {
      container.stations$.first(result => result.size > 0).subscribe(result => {
        fixture.detectChanges();

        expect(container.stations.size).to.equal(3);

        const elmap: HTMLElement = deMap.nativeElement;
        const stationsMarkers: number = elmap.firstElementChild.childElementCount - 1;
        expect(stationsMarkers).to.equal(3);

        expect(mapComponent.stations.count()).to.equal(3);

        done();
      });
    });
    it('should not render any forecast', () => {
      const forecastEl = fixture.debugElement.query(By.css('weather-forecast'));
      expect(forecastEl).to.equal(null);
    });
//.........这里部分代码省略.........
开发者ID:atSistemas,项目名称:angular-base,代码行数:101,代码来源:weather.container.spec.ts

示例3: beforeEach

 beforeEach(() => {
   server = fakeServer.create();
   server.respondWith(
     'GET',
     OWM_API_STATION(),
     fakeResponse(200, MockStations)
   );
   server.respondWith(
     'GET',
     OWM_API_FORECAST(lat, lon),
     fakeResponse(200, MockForecasts)
   );
   server.respondImmediately = true;
 });
开发者ID:atSistemas,项目名称:angular-base,代码行数:14,代码来源:weather-map.service.spec.ts

示例4: it

    it('sends a request to Sentry servers', async () => {
      server.respondWith('POST', transportUrl, [200, {}, '']);

      return transport.sendEvent(payload).then(res => {
        expect(res.status).equal(Status.Success);
        const request = server.requests[0];
        expect(server.requests.length).equal(1);
        expect(request.method).equal('POST');
        expect(JSON.parse(request.requestBody)).deep.equal(payload);
      });
    });
开发者ID:getsentry,项目名称:raven-js,代码行数:11,代码来源:xhr.test.ts

示例5: afterEach

 afterEach(() => {
   server.restore();
 });
开发者ID:getsentry,项目名称:raven-js,代码行数:3,代码来源:xhr.test.ts

示例6: afterEach

 afterEach(() => {
   TestBed.resetTestingModule();
   server.restore();
 });
开发者ID:atSistemas,项目名称:angular-base,代码行数:4,代码来源:weather-map.service.spec.ts

示例7: afterEach

 afterEach(() => {
   container.ngOnDestroy();
   TestBed.resetTestingModule();
   server.restore();
 });
开发者ID:atSistemas,项目名称:angular-base,代码行数:5,代码来源:weather.container.spec.ts

示例8:

		afterEach((): void => {
			deviceName.remove();
			fakeServer.restore();
		});
开发者ID:scottohara,项目名称:tvmanager,代码行数:4,代码来源:registration-controller_spec.ts


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