From bf32eb7dfcb88f7b2cedcaff7ce36484876347b3 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Fri, 6 Mar 2015 08:58:06 -0500 Subject: [PATCH] test retain flag --- tests/mithril-tests.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 10e37c9e..26b37fb2 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -2589,6 +2589,44 @@ function testMithril(mock) { return initCount == 1 }) + test(function() { + //retain flag should work inside component + mock.requestAnimationFrame.$resolve() + mock.location.search = "?" + + var root = mock.document.createElement("div") + var initCount = 0 + + var a = {} + a.controller = function() {} + a.view = function() { + return m("div", m("a", {config: function(el, init, ctx) { + ctx.retain = true + if (!init) initCount++ + }})) + } + + var b = {} + b.controller = function() {m.redraw.strategy("diff")} + b.view = function() { + return m("section", m("a", {config: function(el, init, ctx) { + ctx.retain = true + if (!init) initCount++ + }})) + } + + m.route(root, "/a", { + "/a": {view: function() {return m("div", a)}}, + "/b": {view: function() {return m("div", b)}}, + }) + mock.requestAnimationFrame.$resolve() + + m.route("/b") + + mock.requestAnimationFrame.$resolve() + + return initCount == 1 + }) //end m.route //m.prop