Skip to content

Commit

Permalink
fix: check headers setup in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluf22 committed Nov 16, 2022
1 parent 1249920 commit 39a29a6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/utils/__tests__/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe("request", () => {
const sendBeacon = jest.fn(() => true);
const open = jest.fn();
const send = jest.fn();
const setRequestHeader = jest.fn();
const write = jest.fn();

beforeEach(() => {
Expand All @@ -29,6 +30,7 @@ describe("request", () => {
window.XMLHttpRequest = function() {
this.open = open;
this.send = send;
this.setRequestHeader = setRequestHeader;
};
nodeHttpRequest.mockImplementation(() => {
return {
Expand Down Expand Up @@ -66,6 +68,7 @@ describe("request", () => {
);
expect(open).not.toHaveBeenCalled();
expect(send).not.toHaveBeenCalled();
expect(setRequestHeader).not.toHaveBeenCalled();
expect(nodeHttpRequest).not.toHaveBeenCalled();
expect(nodeHttpsRequest).not.toHaveBeenCalled();
});
Expand All @@ -80,6 +83,7 @@ describe("request", () => {
request(url, data);
expect(navigator.sendBeacon).not.toHaveBeenCalled();
expect(open).toHaveBeenCalledTimes(1);
expect(setRequestHeader).toHaveBeenCalledTimes(2);
expect(open).toHaveBeenLastCalledWith("POST", url);
expect(send).toHaveBeenCalledTimes(1);
expect(send).toHaveBeenLastCalledWith(JSON.stringify(data));
Expand All @@ -99,6 +103,7 @@ describe("request", () => {
expect(navigator.sendBeacon).toHaveBeenCalledTimes(1);

expect(open).toHaveBeenCalledTimes(1);
expect(setRequestHeader).toHaveBeenCalledTimes(2);
expect(open).toHaveBeenLastCalledWith("POST", url);
expect(send).toHaveBeenCalledTimes(1);
expect(send).toHaveBeenLastCalledWith(JSON.stringify(data));
Expand All @@ -117,6 +122,7 @@ describe("request", () => {
expect(navigator.sendBeacon).not.toHaveBeenCalled();
expect(open).not.toHaveBeenCalled();
expect(send).not.toHaveBeenCalled();
expect(setRequestHeader).not.toHaveBeenCalled();
expect(nodeHttpsRequest).not.toHaveBeenCalled();
expect(nodeHttpRequest).toHaveBeenLastCalledWith({
protocol: "http:",
Expand All @@ -143,6 +149,7 @@ describe("request", () => {
request(url, data);
expect(navigator.sendBeacon).not.toHaveBeenCalled();
expect(open).not.toHaveBeenCalled();
expect(setRequestHeader).not.toHaveBeenCalled();
expect(send).not.toHaveBeenCalled();
expect(nodeHttpRequest).not.toHaveBeenCalled();
expect(nodeHttpsRequest).toHaveBeenLastCalledWith({
Expand Down

0 comments on commit 39a29a6

Please sign in to comment.