backend_srv_specs.ts 874 B

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