mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
33 lines
820 B
TypeScript
33 lines
820 B
TypeScript
import angular from 'angular';
|
|
import { BackendSrv } from 'app/core/services/backend_srv';
|
|
import { ContextSrv } from '../services/context_srv';
|
|
jest.mock('app/core/store');
|
|
|
|
describe('backend_srv', () => {
|
|
const _httpBackend = (options: any) => {
|
|
if (options.url === 'gateway-error') {
|
|
return Promise.reject({ status: 502 });
|
|
}
|
|
return Promise.resolve({});
|
|
};
|
|
|
|
const _backendSrv = new BackendSrv(
|
|
_httpBackend,
|
|
{} as angular.IQService,
|
|
{} as angular.ITimeoutService,
|
|
{} as ContextSrv
|
|
);
|
|
|
|
describe('when handling errors', () => {
|
|
it('should return the http status code', async () => {
|
|
try {
|
|
await _backendSrv.datasourceRequest({
|
|
url: 'gateway-error',
|
|
});
|
|
} catch (err) {
|
|
expect(err.status).toBe(502);
|
|
}
|
|
});
|
|
});
|
|
});
|