diff --git a/src/idiomorph.js b/src/idiomorph.js index 257c040..ab21454 100644 --- a/src/idiomorph.js +++ b/src/idiomorph.js @@ -1085,7 +1085,8 @@ var Idiomorph = (function () { * @returns {Element[]} */ function findIdElements(root) { - let elements = Array.from(root.querySelectorAll("[id]")); + // root could be a text or comment node which doesn't have `querySelectorAll` + let elements = Array.from(root.querySelectorAll?.("[id]") ?? []); // root could be a document fragment which doesn't have `getAttribute` if (root.getAttribute?.("id")) { elements.push(root); diff --git a/test/core.js b/test/core.js index 5e10210..7d559c8 100644 --- a/test/core.js +++ b/test/core.js @@ -121,6 +121,28 @@ describe("Core morphing tests", function () { ); }); + it("morphs outerHTML properly when oldNode is a text node", function () { + let parent = make("
Foo
"); + let initial = parent.firstChild; + Idiomorph.morph(initial, "", { + morphStyle: "outerHTML", + }); + parent.innerHTML.should.equal(""); + }); + + it("morphs outerHTML properly when oldNode is a comment node", function () { + let parent = make( + "

Before

After

", + ); + let initial = parent.childNodes[1]; + Idiomorph.morph(initial, "", { + morphStyle: "outerHTML", + }); + parent.innerHTML.should.equal( + "

Before

After

", + ); + }); + it("morphs innerHTML as content properly when argument is null", function () { let initial = make("
Foo
"); Idiomorph.morph(initial, null, { morphStyle: "innerHTML" });