From 118da88889c1e604b42bef67cb67aacfd1b711a4 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Sat, 17 Sep 2016 22:43:38 +0200 Subject: [PATCH] Add test for keys on routed components --- api/tests/test-router.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/api/tests/test-router.js b/api/tests/test-router.js index d43f0b44..a8cd1ac2 100644 --- a/api/tests/test-router.js +++ b/api/tests/test-router.js @@ -293,6 +293,32 @@ o.spec("route", function() { o(root.firstChild.nodeName).equals("DIV") }) + o("changing `vnode.key` in `render` resets the component", function(done, timeout){ + timeout(FRAME_BUDGET * 3) + + var oninit = o.spy() + var Component = { + oninit: oninit, + view: function(){ + return m("div") + } + } + $window.location.href = prefix + "/abc" + route(root, "/abc", { + "/:id": {render: function(vnode) { + return m(Component, {key: vnode.attrs.id}) + }} + }) + setTimeout(function(){ + o(oninit.callCount).equals(1) + route.set('/def') + setTimeout(function(){ + o(oninit.callCount).equals(2) + done() + }, FRAME_BUDGET) + }, FRAME_BUDGET) + }) + o("accepts RouteResolver without `onmatch` method as payload", function() { var renderCount = 0 var Component = {