Skip to content

Commit

Permalink
failing test for returning false to beforeNodeMorphed during pantry r…
Browse files Browse the repository at this point in the history
…estore.
  • Loading branch information
botandrose-machine committed Dec 23, 2024
1 parent d118b2b commit 6c74093
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 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,40 @@ 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>
<p id="first">First paragraph</p>
<p id="second">Second paragraph</p>
</div>
`),
);
document.getElementById("first").innerHTML = "First paragraph EDITED";
document.getElementById("second").innerHTML = "Second paragraph EDITED";

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

getWorkArea().innerHTML.should.equal(`
<div>
<p id="second">Second paragraph EDITED</p>
<p id="first">First paragraph EDITED</p>
</div>
`);
});
});

0 comments on commit 6c74093

Please sign in to comment.