From e32dfccbd9156313f5c36220313dc822db406735 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 13 Oct 2022 15:39:23 +0100 Subject: [PATCH] Additional tests for 'url' property to satisfy code coverage --- spec/unit/http-api/utils.spec.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/unit/http-api/utils.spec.ts b/spec/unit/http-api/utils.spec.ts index 6630b0199..4dec92e91 100644 --- a/spec/unit/http-api/utils.spec.ts +++ b/spec/unit/http-api/utils.spec.ts @@ -114,6 +114,32 @@ describe("parseErrorResponse", () => { }, 500)); }); + it("should resolve Matrix Errors from XHR with urls", () => { + expect(parseErrorResponse({ + responseURL: "https://example.com", + getResponseHeader(name: string): string | null { + return name === "Content-Type" ? "application/json" : null; + }, + status: 500, + } as XMLHttpRequest, '{"errcode": "TEST"}')).toStrictEqual(new MatrixError({ + errcode: "TEST", + }, 500, "https://example.com")); + }); + + it("should resolve Matrix Errors from fetch with urls", () => { + expect(parseErrorResponse({ + url: "https://example.com", + headers: { + get(name: string): string | null { + return name === "Content-Type" ? "application/json" : null; + }, + }, + status: 500, + } as Response, '{"errcode": "TEST"}')).toStrictEqual(new MatrixError({ + errcode: "TEST", + }, 500, "https://example.com")); + }); + it("should handle no type gracefully", () => { expect(parseErrorResponse({ headers: {