當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。