瀏覽代碼

Merge pull request #12742 from dehrax/12224-backend-srv

Karma to Jest: backend_srv
Marcus Efraimsson 7 年之前
父節點
當前提交
710566e146
共有 2 個文件被更改,包括 25 次插入31 次删除
  1. 25 0
      public/app/core/specs/backend_srv.jest.ts
  2. 0 31
      public/app/core/specs/backend_srv_specs.ts

+ 25 - 0
public/app/core/specs/backend_srv.jest.ts

@@ -0,0 +1,25 @@
+import { BackendSrv } from 'app/core/services/backend_srv';
+jest.mock('app/core/store');
+
+describe('backend_srv', function() {
+  let _httpBackend = options => {
+    if (options.url === 'gateway-error') {
+      return Promise.reject({ status: 502 });
+    }
+    return Promise.resolve({});
+  };
+
+  let _backendSrv = new BackendSrv(_httpBackend, {}, {}, {}, {});
+
+  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);
+      }
+    });
+  });
+});

+ 0 - 31
public/app/core/specs/backend_srv_specs.ts

@@ -1,31 +0,0 @@
-import { describe, beforeEach, it, expect, angularMocks } from 'test/lib/common';
-import 'app/core/services/backend_srv';
-
-describe('backend_srv', function() {
-  var _backendSrv;
-  var _httpBackend;
-
-  beforeEach(angularMocks.module('grafana.core'));
-  beforeEach(angularMocks.module('grafana.services'));
-  beforeEach(
-    angularMocks.inject(function($httpBackend, $http, backendSrv) {
-      _httpBackend = $httpBackend;
-      _backendSrv = backendSrv;
-    })
-  );
-
-  describe('when handling errors', function() {
-    it('should return the http status code', function(done) {
-      _httpBackend.whenGET('gateway-error').respond(502);
-      _backendSrv
-        .datasourceRequest({
-          url: 'gateway-error',
-        })
-        .catch(function(err) {
-          expect(err.status).to.be(502);
-          done();
-        });
-      _httpBackend.flush();
-    });
-  });
-});