Skip to content

Commit 9d647f8

Browse files
committed
trim name option
1 parent 2e61d77 commit 9d647f8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Hook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Hook {
5858
_tap(type, options, fn) {
5959
if (typeof options === "string") {
6060
options = {
61-
name: options
61+
name: options.trim()
6262
};
6363
} else if (typeof options !== "object" || options === null) {
6464
throw new Error("Invalid tap options");

lib/__tests__/Hook.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,13 @@ describe("Hook", () => {
6767
hook.call();
6868
expect(calls).toEqual(["E", "F", "C", "D", "B", "A"]);
6969
});
70+
it("should throw without a valid name", () => {
71+
const hook = new SyncHook();
72+
expect(() => hook.tap("", () => {})).toThrow(
73+
new Error("Missing name for tap")
74+
);
75+
expect(() => hook.tap(" ", () => {})).toThrow(
76+
new Error("Missing name for tap")
77+
);
78+
});
7079
});

0 commit comments

Comments
 (0)