Skip to content

Commit

Permalink
fix: improve test asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Jan 21, 2022
1 parent 6a3c518 commit d43f46b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/JsonService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { ErrorResponse } from "./errors";
import { JsonService } from "./JsonService";

import { mocked } from "jest-mock";

describe("JsonService", () => {
Expand All @@ -18,21 +19,27 @@ 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 () => {
// act
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 () => {
Expand Down

0 comments on commit d43f46b

Please sign in to comment.