backend_srv_specs.ts 885 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import {
  2. describe,
  3. beforeEach,
  4. it,
  5. expect,
  6. angularMocks,
  7. } from 'test/lib/common';
  8. import 'app/core/services/backend_srv';
  9. describe('backend_srv', function() {
  10. var _backendSrv;
  11. var _httpBackend;
  12. beforeEach(angularMocks.module('grafana.core'));
  13. beforeEach(angularMocks.module('grafana.services'));
  14. beforeEach(
  15. angularMocks.inject(function($httpBackend, $http, backendSrv) {
  16. _httpBackend = $httpBackend;
  17. _backendSrv = backendSrv;
  18. })
  19. );
  20. describe('when handling errors', function() {
  21. it('should return the http status code', function(done) {
  22. _httpBackend.whenGET('gateway-error').respond(502);
  23. _backendSrv
  24. .datasourceRequest({
  25. url: 'gateway-error',
  26. })
  27. .catch(function(err) {
  28. expect(err.status).to.be(502);
  29. done();
  30. });
  31. _httpBackend.flush();
  32. });
  33. });
  34. });