mirror of
https://github.com/prymitive/karma
synced 2026-05-21 04:33:07 +00:00
Right now configured headers are only set on requests made from the backend to alertmanager API. With this change fetch() calls in the browser will use those headers if proxy mode is not enabled.
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import { FetchWithCredentials } from "./Fetch";
|
|
|
|
beforeEach(() => {
|
|
fetch.resetMocks();
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
describe("FetchWithCredentials", () => {
|
|
it("fetch passes '{credentials: include}' to all requests", async () => {
|
|
const request = FetchWithCredentials("http://example.com", {});
|
|
await expect(request).resolves.toBeUndefined();
|
|
expect(fetch).toHaveBeenCalledWith("http://example.com", {
|
|
credentials: "include"
|
|
});
|
|
});
|
|
|
|
it("custom keys are merged with defaults", async () => {
|
|
const request = FetchWithCredentials("http://example.com", {
|
|
foo: "bar"
|
|
});
|
|
await expect(request).resolves.toBeUndefined();
|
|
expect(fetch).toHaveBeenCalledWith("http://example.com", {
|
|
credentials: "include",
|
|
foo: "bar"
|
|
});
|
|
});
|
|
|
|
it("custom credentials are used when passed", async () => {
|
|
const request = FetchWithCredentials("http://example.com", {
|
|
credentials: "none"
|
|
});
|
|
await expect(request).resolves.toBeUndefined();
|
|
expect(fetch).toHaveBeenCalledWith("http://example.com", {
|
|
credentials: "none"
|
|
});
|
|
});
|
|
});
|