@dasch-swiss/dsp-js
Version:
JavaScript library that handles API requests to Knora
32 lines • 1.87 kB
JavaScript
import { AjaxError, AjaxResponse } from "rxjs/ajax";
import { ApiResponseData } from "./api-response-data";
import { ApiResponseError } from "./api-response-error";
describe("Test class ApiResponseError", function () {
describe("Test method fromAjaxError()", function () {
var ajaxError = new AjaxError("Error", new XMLHttpRequest(), { url: "test-url", method: "GET", async: true, headers: {}, timeout: 0, user: undefined, password: undefined, crossDomain: false, responseType: "json", withCredentials: false });
var apiResponseError = ApiResponseError.fromAjaxError(ajaxError);
it("should be an instance of ApiResponseError", function () {
expect(apiResponseError).toEqual(jasmine.any(ApiResponseError));
});
it("should store the original error", function () {
expect(apiResponseError.error).toBe(ajaxError);
});
});
describe("Test method fromErrorString()", function () {
var errorString = "Error string";
var mockXhr = {
getAllResponseHeaders: function () { return ""; },
status: 200,
statusText: "OK"
};
var responseData = ApiResponseData.fromAjaxResponse(new AjaxResponse({}, mockXhr, { url: "test-url", method: "GET", async: true, headers: {}, timeout: 0, user: undefined, password: undefined, crossDomain: false, responseType: "json", withCredentials: false }));
var apiResponseError = ApiResponseError.fromErrorString(errorString, responseData);
it("should be an instance of ApiResponseError", function () {
expect(apiResponseError).toEqual(jasmine.any(ApiResponseError));
});
it("should store the original error", function () {
expect(apiResponseError.error).toBe(errorString);
});
});
});
//# sourceMappingURL=api-response-error.spec.js.map