Skip to content

Commit

Permalink
failing test for returning fallse to beforeNodeMorphed during pantry …
Browse files Browse the repository at this point in the history
…restore.
  • Loading branch information
botandrose-machine committed Dec 23, 2024
1 parent d118b2b commit 894fb60
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions test/two-pass.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
describe("Two-pass option for retaining more state", function () {
beforeEach(function () {
clearWorkArea();
});
setup();

it("fails to preserve all non-attribute element state with single-pass option", function () {
getWorkArea().append(
Expand Down Expand Up @@ -428,4 +426,42 @@ describe("Two-pass option for retaining more state", function () {
],
]);
});

it("beforeNodeMorphed hook also applies to nodes restored from the pantry", function () {
getWorkArea().append(
make(`
<div>
<textarea id="first">First paragraph</textarea>
<textarea id="second">Second paragraph</textarea>
</div>
`),
);
document.getElementById("first").value = "First paragraph EDITED";
document.getElementById("second").value = "Second paragraph EDITED";

let finalSrc = `
<div>
<textarea id="second">Second paragraph</textarea>
<textarea id="first">First paragraph</textarea>
</div>
`;
Idiomorph.morph(getWorkArea(), finalSrc, {
morphStyle: "innerHTML",
twoPass: true,
callbacks: {
beforeNodeMorphed(oldNode, newContent) {
if (oldNode.tagName === "TEXTAREA") return false;
},
},
});

// textarea value properties don't automatically reflect in html, so manually sync for the assertion
getWorkArea().querySelectorAll("textarea").forEach(e => e.innerHTML = e.value)
getWorkArea().innerHTML.should.equal(`
<div>
<textarea id="second">Second paragraph EDITED</textarea>
<textarea id="first">First paragraph EDITED</textarea>
</div>
`);
});
});

0 comments on commit 894fb60

Please sign in to comment.