Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/idiomorph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ describe("Core morphing tests", function () {
);
});

it("morphs outerHTML properly when oldNode is a text node", function () {
let parent = make("<div>Foo</div>");
let initial = parent.firstChild;
Idiomorph.morph(initial, "<button>Bar</button>", {
morphStyle: "outerHTML",
});
parent.innerHTML.should.equal("<button>Bar</button>");
});

it("morphs outerHTML properly when oldNode is a comment node", function () {
let parent = make(
"<div><p>Before</p><!-- placeholder --><p>After</p></div>",
);
let initial = parent.childNodes[1];
Idiomorph.morph(initial, "<button>Bar</button>", {
morphStyle: "outerHTML",
});
parent.innerHTML.should.equal(
"<p>Before</p><button>Bar</button><p>After</p>",
);
});

it("morphs innerHTML as content properly when argument is null", function () {
let initial = make("<div>Foo</div>");
Idiomorph.morph(initial, null, { morphStyle: "innerHTML" });
Expand Down
Loading