From d43f46b210f2a435ab5021f9a9731c0872a89ea0 Mon Sep 17 00:00:00 2001 From: pamapa Date: Fri, 21 Jan 2022 08:16:13 +0100 Subject: [PATCH] fix: improve test asserts --- src/JsonService.test.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/JsonService.test.ts b/src/JsonService.test.ts index 5c65f9d0e..9a0a13def 100644 --- a/src/JsonService.test.ts +++ b/src/JsonService.test.ts @@ -3,6 +3,7 @@ import { ErrorResponse } from "./errors"; import { JsonService } from "./JsonService"; + import { mocked } from "jest-mock"; describe("JsonService", () => { @@ -18,10 +19,13 @@ describe("JsonService", () => { await expect(subject.getJson("http://test")).rejects.toThrow(); // assert - expect(fetch).toBeCalledWith("http://test", { - headers: { Accept: "application/json" }, - method: "GET", - }); + expect(fetch).toBeCalledWith( + "http://test", + expect.objectContaining({ + headers: { Accept: "application/json" }, + method: "GET", + }), + ); }); it("should set token as authorization header", async () => { @@ -29,10 +33,13 @@ describe("JsonService", () => { await expect(subject.getJson("http://test", "token")).rejects.toThrow(); // assert - expect(fetch).toBeCalledWith("http://test", { - headers: { Accept: "application/json", Authorization: "Bearer token" }, - method: "GET", - }); + expect(fetch).toBeCalledWith( + "http://test", + expect.objectContaining({ + headers: { Accept: "application/json", Authorization: "Bearer token" }, + method: "GET", + }), + ); }); it("should fulfill promise when http response is 200", async () => {