Skip to content

Commit 934bc55

Browse files
authored
fix: missing trim() for name when options is an object (#197)
1 parent d3e85d0 commit 934bc55

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Hook.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ class Hook {
6666
_tap(type, options, fn) {
6767
if (typeof options === "string") {
6868
options = {
69-
name: options.trim()
69+
name: options
7070
};
7171
} else if (typeof options !== "object" || options === null) {
7272
throw new Error("Invalid tap options");
7373
}
74+
if (typeof options.name === "string") {
75+
options.name = options.name.trim();
76+
}
7477
if (typeof options.name !== "string" || options.name === "") {
7578
throw new Error("Missing name for tap");
7679
}

lib/__tests__/Hook.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,11 @@ describe("Hook", () => {
100100
expect(() => hook.tap(" ", () => {})).toThrow(
101101
new Error("Missing name for tap")
102102
);
103+
expect(() => hook.tap({ name: "" }, () => {})).toThrow(
104+
new Error("Missing name for tap")
105+
);
106+
expect(() => hook.tap({ name: " " }, () => {})).toThrow(
107+
new Error("Missing name for tap")
108+
);
103109
});
104110
});

0 commit comments

Comments
 (0)