Checked for empty selectors.
h3rald h3rald@h3rald.com
Sun, 12 Jul 2020 09:35:15 +0200
2 files changed,
5 insertions(+),
5 deletions(-)
M
__tests__/h3.js
→
__tests__/h3.js
@@ -50,6 +50,7 @@ const invalid2nd2 = () => h3("div", true, []);
const invalid2nd3 = () => h3("div", null, []); const invalidChildren = () => h3("div", ["test", 1, 2]); const tooManyArgs = () => h3("div", { id: "test" }, "test", "aaa"); + const emptySelector = () => h3(""); expect(empty).toThrowError(/No arguments passed/); expect(invalid1st).toThrowError(/Invalid first argument/); expect(invalid1st2).toThrowError(/Invalid first argument/);@@ -61,6 +62,7 @@ expect(invalid2nd2).toThrowError(/Invalid second argument/);
expect(invalid2nd3).toThrowError(/Invalid second argument/); expect(invalidChildren).toThrowError(/not a VNode: 1/); expect(tooManyArgs).toThrowError(/Too many arguments/); + expect(emptySelector).toThrowError(/Invalid selector/); }); it("should support the creation of elements with a single, non-array child", () => {@@ -400,12 +402,12 @@ it("should not redraw while a other redraw is in progress", async () => {
const vnode = h3("div"); await h3.init({ routes: { - "/": () => vnode + "/": () => vnode, }, }); jest.spyOn(vnode, "redraw"); h3.redraw(true); - h3.redraw() + h3.redraw(); expect(vnode.redraw).toHaveBeenCalledTimes(1); }); });
M
h3.js
→
h3.js
@@ -41,8 +41,6 @@ return false;
} } if ([String, Number, Boolean].includes(obj1.constructor)) { - if (obj1 !== obj2) { - } return obj1 === obj2; } if (obj1.constructor === Array) {@@ -207,7 +205,7 @@ delete this.attributes.classList;
} processSelector(selector) { - if (!selector.match(selectorRegex)) { + if (!selector.match(selectorRegex) || selector.length === 0) { throw new Error(`[VNode] Invalid selector: ${selector}`); } const [, type, id, classes] = selector.match(selectorRegex);