本文整理匯總了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();
});