From ceacf5716cf474a9d96aa629785faa51aace07ed Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Thu, 18 Feb 2021 14:21:52 -0700 Subject: [PATCH] fix(typescript): compile-time invalid argument errors (#465) Co-authored-by: Gareth Jones Co-authored-by: Oscar Dominguez --- test/integration/server-test.ts | 11 +++-------- test/integration/sign-test.ts | 3 ++- test/unit/event-handler-on-test.ts | 12 +++++------- 3 files changed, 10 insertions(+), 16 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) => { 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..460b9c42 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)).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", () => { - expect(() => - receiverOn(state, "error" as EmitterWebhookEventName, noop) - ).toThrowError( + // @ts-expect-error + 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' ); });