Skip to content

Commit

Permalink
test(server-test): mock errorHandler using jest.fn() (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscard0m authored and wolfy1339 committed Aug 22, 2020
1 parent 0b3757f commit 1cd9000
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions test/integration/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import FakeTimers from "@sinonjs/fake-timers";
import axios, { AxiosError, AxiosResponse } from "axios";
import getPort from "get-port";
import { promisify } from "util";
import simple from "simple-mock";
import { Webhooks } from "../../src";
import pushEventPayload from "../fixtures/push-payload.json";
import { WebhookError } from "../../src/types";
Expand Down Expand Up @@ -146,7 +145,7 @@ test("POST / with push event payload (no signature)", (t) => {
secret: "mysecret",
});
const server = http.createServer(api.middleware);
const errorHandler = simple.spy(undefined);
const errorHandler = jest.fn();
api.on("error", errorHandler);

promisify(server.listen.bind(server))(this.port)
Expand All @@ -169,7 +168,7 @@ test("POST / with push event payload (no signature)", (t) => {
})

.then(() => {
expect(errorHandler.callCount).toBe(1); // calls "error" event handler
expect(errorHandler).toHaveBeenCalled(); // calls "error" event handler
server.close(t);
})

Expand All @@ -181,7 +180,7 @@ test("POST / with push event payload (invalid signature)", (t) => {
secret: "mysecret",
});
const server = http.createServer(api.middleware);
const errorHandler = simple.spy();
const errorHandler = jest.fn();
api.on("error", errorHandler);

promisify(server.listen.bind(server))(this.port)
Expand All @@ -205,7 +204,7 @@ test("POST / with push event payload (invalid signature)", (t) => {
})

.then(() => {
expect(errorHandler.callCount).toBe(1); // calls "error" event handler
expect(errorHandler).toHaveBeenCalled(); // calls "error" event handler
server.close(t);
})

Expand Down

0 comments on commit 1cd9000

Please sign in to comment.