From dbed8b49c2cd8a7cb94b69d0c16a5b1f2a01b045 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Fri, 12 Feb 2021 11:55:33 -0700 Subject: [PATCH 1/3] style(test): use standard .toThrow() matcher --- test/integration/server-test.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/test/integration/server-test.ts b/test/integration/server-test.ts index c33f6a22..f9fbbfba 100644 --- a/test/integration/server-test.ts +++ b/test/integration/server-test.ts @@ -21,14 +21,9 @@ describe("server-test", () => { }); }); - test("initialised without options", (t) => { - try { - // @ts-expect-error - new Webhooks(); - t.fail("should throw error"); - } catch (error) { - t(); - } + test("initialised without options", () => { + // @ts-expect-error + expect(() => new Webhooks()).toThrow(); }); test("GET /", (t) => { From 358149a587169bde723add1c45e835e62dcd5aa0 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Fri, 12 Feb 2021 11:44:05 -0700 Subject: [PATCH 2/3] test(typescript): compile-time invalid argument errors --- test/integration/sign-test.ts | 3 ++- test/unit/event-handler-on-test.ts | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/test/integration/sign-test.ts b/test/integration/sign-test.ts index 120fe5cd..aac9f5d2 100644 --- a/test/integration/sign-test.ts +++ b/test/integration/sign-test.ts @@ -22,7 +22,8 @@ test("sign(secret) without eventPayload throws", () => { test("sign({secret, algorithm}) with invalid algorithm throws", () => { expect(() => - sign.bind(null, { secret, algorithm: "sha2" as "sha1" }, eventPayload)() + // @ts-expect-error + sign.bind(null, { secret, algorithm: "sha2" }, eventPayload)() ).toThrow(); }); diff --git a/test/unit/event-handler-on-test.ts b/test/unit/event-handler-on-test.ts index cffbc06b..19c5f1c5 100644 --- a/test/unit/event-handler-on-test.ts +++ b/test/unit/event-handler-on-test.ts @@ -1,5 +1,5 @@ import { receiverOn } from "../../src/event-handler/on"; -import { EmitterWebhookEventName, State } from "../../src/types"; +import { State } from "../../src/types"; function noop() {} @@ -24,17 +24,15 @@ test("receiver.on with invalid event name", () => { }); test("receiver.on with event name of '*' throws an error", () => { - expect(() => - receiverOn(state, "*" as EmitterWebhookEventName, noop) - ).toThrowError( + // @ts-expect-error + expect(() => receiverOn(state, "*", noop)).toThrowError( 'Using the "*" event with the regular Webhooks.on() function is not supported. Please use the Webhooks.onAny() method instead' ); }); test("receiver.on with event name of 'error' throws an error", () => { - expect(() => - receiverOn(state, "error" as EmitterWebhookEventName, noop) - ).toThrowError( + // @ts-expect-error + expect(() => receiverOn(state, "error", noop)).toThrowError( 'Using the "error" event with the regular Webhooks.on() function is not supported. Please use the Webhooks.onError() method instead' ); }); From 2b297f9daf0ed1ebbd36b357c53f36f888156c76 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Sun, 14 Feb 2021 13:09:27 -0700 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Gareth Jones --- test/unit/event-handler-on-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/event-handler-on-test.ts b/test/unit/event-handler-on-test.ts index 19c5f1c5..460b9c42 100644 --- a/test/unit/event-handler-on-test.ts +++ b/test/unit/event-handler-on-test.ts @@ -25,14 +25,14 @@ test("receiver.on with invalid event name", () => { test("receiver.on with event name of '*' throws an error", () => { // @ts-expect-error - expect(() => receiverOn(state, "*", noop)).toThrowError( + expect(() => receiverOn(state, "*", noop)).toThrow( 'Using the "*" event with the regular Webhooks.on() function is not supported. Please use the Webhooks.onAny() method instead' ); }); test("receiver.on with event name of 'error' throws an error", () => { // @ts-expect-error - expect(() => receiverOn(state, "error", noop)).toThrowError( + expect(() => receiverOn(state, "error", noop)).toThrow( 'Using the "error" event with the regular Webhooks.on() function is not supported. Please use the Webhooks.onError() method instead' ); });