backend_srv.test.ts 813 B

1234567891011121314151617181920212223242526272829303132
  1. import angular from 'angular';
  2. import { BackendSrv } from 'app/core/services/backend_srv';
  3. import { ContextSrv } from '../services/context_srv';
  4. jest.mock('app/core/store');
  5. describe('backend_srv', () => {
  6. const _httpBackend = options => {
  7. if (options.url === 'gateway-error') {
  8. return Promise.reject({ status: 502 });
  9. }
  10. return Promise.resolve({});
  11. };
  12. const _backendSrv = new BackendSrv(
  13. _httpBackend,
  14. {} as angular.IQService,
  15. {} as angular.ITimeoutService,
  16. {} as ContextSrv
  17. );
  18. describe('when handling errors', () => {
  19. it('should return the http status code', async () => {
  20. try {
  21. await _backendSrv.datasourceRequest({
  22. url: 'gateway-error',
  23. });
  24. } catch (err) {
  25. expect(err.status).toBe(502);
  26. }
  27. });
  28. });
  29. });