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 eb796d0
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 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,45 @@ 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 data-preserve-me="true" id="first">First paragraph</p>
<p data-preserve-me="true" id="second">Second paragraph</p>
</div>
`),
);
document.getElementById("first").innerHTML = "First paragraph EDITED";
document.getElementById("second").innerHTML = "Second paragraph EDITED";

let finalSrc = `
<div>
<p data-preserve-me="true" id="second">Second paragraph</p>
<p data-preserve-me="true" id="first">First paragraph</p>
</div>
`;

Idiomorph.morph(getWorkArea(), finalSrc, {
morphStyle: "innerHTML",
twoPass: true,
callbacks: {
// basic implementation of a preserve-me attr
beforeNodePantried(node) {
if (node.parentNode?.dataset?.preserveMe) return false;
},
beforeNodeMorphed(oldNode, newContent) {
if (oldNode.dataset?.preserveMe) return false;
},
},
});

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

0 comments on commit eb796d0

Please sign in to comment.