From 605fa447111711b28aba24570d34f7f5a0230b05 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Thu, 8 Dec 2016 15:18:37 +0100 Subject: [PATCH] [api/router] Test for two deferred onmatch racing --- api/tests/test-router.js | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/api/tests/test-router.js b/api/tests/test-router.js index 7ea00195..7424e929 100644 --- a/api/tests/test-router.js +++ b/api/tests/test-router.js @@ -932,6 +932,63 @@ o.spec("route", function() { }) }) + o.only("when two async routes are racing, the last one set cancels the finalization of the first", function(done) { + var renderA = o.spy() + var renderB = o.spy() + var onmatchA = o.spy(function(){ + return new Promise(function(fulfill) { + setTimeout(function(){ + fulfill() + }, 10) + }) + }) + + $window.location.href = prefix + "/a" + route(root, "/a", { + "/a": { + onmatch: onmatchA, + render: renderA + }, + "/b": { + onmatch: function(){ + var p = new Promise(function(fulfill) { + o(onmatchA.callCount).equals(1) + o(renderA.callCount).equals(0) + o(renderB.callCount).equals(0) + + setTimeout(function(){ + o(onmatchA.callCount).equals(1) + o(renderA.callCount).equals(0) + o(renderB.callCount).equals(0) + + fulfill() + + p.then(function(){ + o(onmatchA.callCount).equals(1) + o(renderA.callCount).equals(0) + o(renderB.callCount).equals(1) + + done() + }) + }, 20) + }) + return p + }, + render: renderB + } + }) + + callAsync(function() { + o(onmatchA.callCount).equals(1) + o(renderA.callCount).equals(0) + o(renderB.callCount).equals(0) + route.set("/b") + o(onmatchA.callCount).equals(1) + o(renderA.callCount).equals(0) + o(renderB.callCount).equals(0) + }) + }) + o("m.route.set(m.route.get()) re-runs the resolution logic (#1180)", function(done){ var onmatch = o.spy() var render = o.spy(function() {return m("div")})