Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/__tests__/AsyncSeriesHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
37 changes: 37 additions & 0 deletions lib/__tests__/SyncWaterfallHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);

Expand Down
4 changes: 2 additions & 2 deletions tapable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class SyncLoopHook<
export class SyncWaterfallHook<
T,
AdditionalOptions = UnsetAdditionalOptions
> extends SyncHook<T, AsArray<T>[0], AdditionalOptions> {}
> extends SyncHook<T, AsArray<T>[0] | void, AdditionalOptions> {}

declare class AsyncHook<
T,
Expand Down Expand Up @@ -137,7 +137,7 @@ export class AsyncSeriesLoopHook<
export class AsyncSeriesWaterfallHook<
T,
AdditionalOptions = UnsetAdditionalOptions
> extends AsyncHook<T, AsArray<T>[0], AdditionalOptions> {}
> extends AsyncHook<T, AsArray<T>[0] | void, AdditionalOptions> {}

type HookFactory<H> = (key: any, hook?: H) => H;

Expand Down
Loading