all repos — h3 @ 0cc724132bcc94a56b0e34990d88b421bc5e105e

A tiny, extremely minimalist JavaScript microframework.

Checked for empty selectors.
h3rald h3rald@h3rald.com
Sun, 12 Jul 2020 09:35:15 +0200
commit

0cc724132bcc94a56b0e34990d88b421bc5e105e

parent

12fe210419c7a04ff5a9d2edc22472f2f14c5967

2 files changed, 5 insertions(+), 5 deletions(-)

jump to
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.jsh3.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);