diff --git a/lib/__tests__/AsyncSeriesHooks.js b/lib/__tests__/AsyncSeriesHooks.js index 807c23c..4a3954f 100644 --- a/lib/__tests__/AsyncSeriesHooks.js +++ b/lib/__tests__/AsyncSeriesHooks.js @@ -71,6 +71,35 @@ describe("AsyncSeriesWaterfallHook", () => { expect(result).toMatchSnapshot(); }); + + it("should work with undefined", async () => { + const hook = new AsyncSeriesWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => undefined); + return expect(hook.promise()).resolves.toBe(42); + }); + + it("should work with void", async () => { + const hook = new AsyncSeriesWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => {}); + return expect(hook.promise()).resolves.toBe(42); + }); + + it("should work with undefined and number again", async () => { + const hook = new AsyncSeriesWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => {}); + hook.tap("number-again", () => 43); + return expect(hook.promise()).resolves.toBe(43); + }); + + it("should work with null", async () => { + const hook = new AsyncSeriesWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => null); + return expect(hook.promise()).resolves.toBeNull(); + }); }); describe("AsyncSeriesLoopHook", () => { diff --git a/lib/__tests__/SyncWaterfallHook.js b/lib/__tests__/SyncWaterfallHook.js index 44da001..15910d3 100644 --- a/lib/__tests__/SyncWaterfallHook.js +++ b/lib/__tests__/SyncWaterfallHook.js @@ -22,6 +22,43 @@ describe("SyncWaterfallHook", () => { ); }); + it("should work", () => { + const hook = new SyncWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("string", () => "str"); + hook.tap("false", () => false); + return expect(hook.call()).toBe(false); + }); + + it("should work with undefined", async () => { + const hook = new SyncWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => undefined); + return expect(hook.call()).toBe(42); + }); + + it("should work with void", async () => { + const hook = new SyncWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => {}); + return expect(hook.call()).toBe(42); + }); + + it("should work with undefined and number again", async () => { + const hook = new SyncWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => {}); + hook.tap("number-again", () => 43); + return expect(hook.call()).toBe(43); + }); + + it("should work with null", async () => { + const hook = new SyncWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => null); + return expect(hook.call()).toBeNull(); + }); + it("should allow to create sync hooks", async () => { const hook = new SyncWaterfallHook(["arg1", "arg2"]); diff --git a/tapable.d.ts b/tapable.d.ts index b16e252..1ab087a 100644 --- a/tapable.d.ts +++ b/tapable.d.ts @@ -95,7 +95,7 @@ export class SyncLoopHook< export class SyncWaterfallHook< T, AdditionalOptions = UnsetAdditionalOptions -> extends SyncHook[0], AdditionalOptions> {} +> extends SyncHook[0] | void, AdditionalOptions> {} declare class AsyncHook< T, @@ -137,7 +137,7 @@ export class AsyncSeriesLoopHook< export class AsyncSeriesWaterfallHook< T, AdditionalOptions = UnsetAdditionalOptions -> extends AsyncHook[0], AdditionalOptions> {} +> extends AsyncHook[0] | void, AdditionalOptions> {} type HookFactory = (key: any, hook?: H) => H;