From eb796d04284bba5133b48bb54c372f495b725ea9 Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Mon, 23 Dec 2024 14:51:22 -0600 Subject: [PATCH] failing test for returning false to beforeNodeMorphed during pantry restore. --- test/two-pass.js | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/test/two-pass.js b/test/two-pass.js index aff806a..f702a4e 100644 --- a/test/two-pass.js +++ b/test/two-pass.js @@ -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( @@ -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(` +
+

First paragraph

+

Second paragraph

+
+ `), + ); + document.getElementById("first").innerHTML = "First paragraph EDITED"; + document.getElementById("second").innerHTML = "Second paragraph EDITED"; + + let finalSrc = ` +
+

Second paragraph

+

First paragraph

+
+ `; + + 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(` +
+

Second paragraph EDITED

+

First paragraph EDITED

+
+ `); + }); });