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
5 changes: 4 additions & 1 deletion lib/Hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ class Hook {
_tap(type, options, fn) {
if (typeof options === "string") {
options = {
name: options.trim()
name: options
};
} else if (typeof options !== "object" || options === null) {
throw new Error("Invalid tap options");
}
if (typeof options.name === "string") {
options.name = options.name.trim();
}
if (typeof options.name !== "string" || options.name === "") {
throw new Error("Missing name for tap");
}
Expand Down
6 changes: 6 additions & 0 deletions lib/__tests__/Hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,11 @@ describe("Hook", () => {
expect(() => hook.tap(" ", () => {})).toThrow(
new Error("Missing name for tap")
);
expect(() => hook.tap({ name: "" }, () => {})).toThrow(
new Error("Missing name for tap")
);
expect(() => hook.tap({ name: " " }, () => {})).toThrow(
new Error("Missing name for tap")
);
});
});