本文整理汇总了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();
});
});
});
示例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);
});
//.........这里部分代码省略.........
示例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;
});
示例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);
});
});
示例5: afterEach
afterEach(() => {
server.restore();
});
示例6: afterEach
afterEach(() => {
TestBed.resetTestingModule();
server.restore();
});
示例7: afterEach
afterEach(() => {
container.ngOnDestroy();
TestBed.resetTestingModule();
server.restore();
});
示例8:
afterEach((): void => {
deviceName.remove();
fakeServer.restore();
});