backend_srv.test.ts 655 B

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