From 28b0de0f889a5f392532cf2db2b16bbb724ddc6f Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Fri, 25 Oct 2024 02:32:38 -0400 Subject: [PATCH] tests: Add tests to test for incorrect insert for deferred mount --- tests/array.test.js | 125 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/tests/array.test.js b/tests/array.test.js index 7edf76f..d663919 100644 --- a/tests/array.test.js +++ b/tests/array.test.js @@ -440,6 +440,131 @@ test("custom component insert order nested", () => { }); }); +test("custom component insert order array nested", () => { + const elem = document.createElement("body"); + + const Comp2 = ({text}) => { + return text; + }; + + const Comp = (props) => { + return h(Comp2, props); + }; + + mount(elem, [ + h(Comp, {text: 1}), + [ + h(Comp, {text: 2}), + [ + h(Comp, {text: 3}), + h(Comp, {text: 4}), + ] + ] + ]); + + assert.deepEqual(elem.tree(), { + name: 'body', + children: ["1", "2", "3", "4"], + }); +}); + +test("custom component insert order array nested inverted", () => { + const elem = document.createElement("body"); + + const Comp2 = ({text}) => { + return text; + }; + + const Comp = (props) => { + return h(Comp2, props); + }; + + mount(elem, [ + [ + [ + h(Comp, {text: 1}), + h(Comp, {text: 2}), + ], + h(Comp, {text: 3}), + ], + h(Comp, {text: 4}), + ]); + + assert.deepEqual(elem.tree(), { + name: 'body', + children: ["1", "2", "3", "4"], + }); +}); + +test("custom component insert order array nested deffered", () => { + const elem = document.createElement("body"); + + const Comp2 = ({text}) => { + return text; + }; + + const Comp = (props) => { + return h(Comp2, props); + }; + + const cont = OArray(); + + mount(elem, [ + h(Comp, {text: 1}), + cont + ]); + + cont.push( + h(props => { + cont.splice(0, 0, + h(Comp, {text: 2}), + h(Comp, {text: 3}), + ); + + return Comp(props); + }, {text: 4}), + ); + + assert.deepEqual(elem.tree(), { + name: 'body', + children: ["1", "2", "3", "4"], + }); +}); + +test("custom component insert order array nested deferred inverted", () => { + const elem = document.createElement("body"); + + const Comp2 = ({text}) => { + return text; + }; + + const Comp = (props) => { + return h(Comp2, props); + }; + + const cont = OArray(); + + mount(elem, [ + cont, + h(Comp, {text: 4}), + ]); + + cont.push( + h(props => { + cont.push( + h(Comp, {text: 2}), + h(Comp, {text: 3}), + ); + return Comp(props) + }, {text: 1}), + ); + + assert.deepEqual(elem.tree(), { + name: 'body', + children: ["1", "2", "3", "4"], + }); +}); + test("custom component mixed with text insert order", () => { const elem = document.createElement("body");