tighten up async testing
This commit is contained in:
parent
846d6ce24b
commit
b6c79f5911
1 changed files with 85 additions and 57 deletions
|
|
@ -5,6 +5,7 @@ var callAsync = require("../../test-utils/callAsync")
|
||||||
var browserMock = require("../../test-utils/browserMock")
|
var browserMock = require("../../test-utils/browserMock")
|
||||||
|
|
||||||
var m = require("../../render/hyperscript")
|
var m = require("../../render/hyperscript")
|
||||||
|
var callAsync = require("../../test-utils/callAsync")
|
||||||
var coreRenderer = require("../../render/render")
|
var coreRenderer = require("../../render/render")
|
||||||
var apiRedraw = require("../../api/redraw")
|
var apiRedraw = require("../../api/redraw")
|
||||||
var apiRouter = require("../../api/router")
|
var apiRouter = require("../../api/router")
|
||||||
|
|
@ -74,7 +75,7 @@ o.spec("route", function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
|
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
@ -82,7 +83,7 @@ o.spec("route", function() {
|
||||||
o($window.location.pathname).equals("/")
|
o($window.location.pathname).equals("/")
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("default route does not inherit params", function(done) {
|
o("default route does not inherit params", function(done) {
|
||||||
|
|
@ -157,11 +158,11 @@ o.spec("route", function() {
|
||||||
o(onclick.args[0].target).equals(root.firstChild)
|
o(onclick.args[0].target).equals(root.firstChild)
|
||||||
|
|
||||||
// Wrapped to give time for the rate-limited redraw to fire
|
// Wrapped to give time for the rate-limited redraw to fire
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(onupdate.callCount).equals(1)
|
o(onupdate.callCount).equals(1)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET * 2)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("event handlers can skip redraw", function(done) {
|
o("event handlers can skip redraw", function(done) {
|
||||||
|
|
@ -192,11 +193,11 @@ o.spec("route", function() {
|
||||||
o(oninit.callCount).equals(1)
|
o(oninit.callCount).equals(1)
|
||||||
|
|
||||||
// Wrapped to ensure no redraw fired
|
// Wrapped to ensure no redraw fired
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(onupdate.callCount).equals(0)
|
o(onupdate.callCount).equals(0)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("changes location on route.link", function() {
|
o("changes location on route.link", function() {
|
||||||
|
|
@ -263,12 +264,12 @@ o.spec("route", function() {
|
||||||
"/:id" : resolver
|
"/:id" : resolver
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(matchCount).equals(1)
|
o(matchCount).equals(1)
|
||||||
o(renderCount).equals(1)
|
o(renderCount).equals(1)
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
done()
|
done()
|
||||||
}, 20)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("accepts RouteResolver without `render` method as payload", function(done) {
|
o("accepts RouteResolver without `render` method as payload", function(done) {
|
||||||
|
|
@ -293,20 +294,18 @@ o.spec("route", function() {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(matchCount).equals(1)
|
o(matchCount).equals(1)
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
done()
|
done()
|
||||||
}, 20)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("changing `vnode.key` in `render` resets the component", function(done, timeout){
|
o("changing `vnode.key` in `render` resets the component", function(done, timeout){
|
||||||
timeout(FRAME_BUDGET * 6)
|
|
||||||
|
|
||||||
var oninit = o.spy()
|
var oninit = o.spy()
|
||||||
var Component = {
|
var Component = {
|
||||||
oninit: oninit,
|
oninit: oninit,
|
||||||
view: function(){
|
view: function() {
|
||||||
return m("div")
|
return m("div")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -316,14 +315,14 @@ o.spec("route", function() {
|
||||||
return m(Component, {key: vnode.attrs.id})
|
return m(Component, {key: vnode.attrs.id})
|
||||||
}}
|
}}
|
||||||
})
|
})
|
||||||
setTimeout(function(){
|
callAsync(function() {
|
||||||
o(oninit.callCount).equals(1)
|
o(oninit.callCount).equals(1)
|
||||||
route.set('/def')
|
route.set('/def')
|
||||||
setTimeout(function(){
|
callAsync(function() {
|
||||||
o(oninit.callCount).equals(2)
|
o(oninit.callCount).equals(2)
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("accepts RouteResolver without `onmatch` method as payload", function() {
|
o("accepts RouteResolver without `onmatch` method as payload", function() {
|
||||||
|
|
@ -377,11 +376,11 @@ o.spec("route", function() {
|
||||||
|
|
||||||
route.set("/b")
|
route.set("/b")
|
||||||
|
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(root.firstChild).equals(dom)
|
o(root.firstChild).equals(dom)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("calls onmatch and view correct number of times", function(done) {
|
o("calls onmatch and view correct number of times", function(done) {
|
||||||
|
|
@ -407,7 +406,7 @@ o.spec("route", function() {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(matchCount).equals(1)
|
o(matchCount).equals(1)
|
||||||
o(renderCount).equals(1)
|
o(renderCount).equals(1)
|
||||||
|
|
||||||
|
|
@ -417,7 +416,7 @@ o.spec("route", function() {
|
||||||
o(renderCount).equals(2)
|
o(renderCount).equals(2)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, 20)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("calls onmatch and view correct number of times when not onmatch returns undefined", function(done) {
|
o("calls onmatch and view correct number of times when not onmatch returns undefined", function(done) {
|
||||||
|
|
@ -442,7 +441,7 @@ o.spec("route", function() {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(matchCount).equals(1)
|
o(matchCount).equals(1)
|
||||||
o(renderCount).equals(1)
|
o(renderCount).equals(1)
|
||||||
|
|
||||||
|
|
@ -452,7 +451,7 @@ o.spec("route", function() {
|
||||||
o(renderCount).equals(2)
|
o(renderCount).equals(2)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, 20)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("onmatch can redirect to another route", function(done) {
|
o("onmatch can redirect to another route", function(done) {
|
||||||
|
|
@ -472,14 +471,39 @@ o.spec("route", function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(redirected).equals(true)
|
o(redirected).equals(true)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("onmatch can redirect to another route that has RouteResolver", function(done) {
|
o("onmatch can redirect to another route that has RouteResolver w/ only onmatch", function(done) {
|
||||||
|
var redirected = false
|
||||||
|
|
||||||
|
$window.location.href = prefix + "/a"
|
||||||
|
route(root, "/a", {
|
||||||
|
"/a" : {
|
||||||
|
onmatch: function() {
|
||||||
|
route.set("/b")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/b" : {
|
||||||
|
onmatch: function() {
|
||||||
|
redirected = true
|
||||||
|
return {view: function() {}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
callAsync(function() {
|
||||||
|
o(redirected).equals(true)
|
||||||
|
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
o("onmatch can redirect to another route that has RouteResolver w/ only render", function(done) {
|
||||||
var redirected = false
|
var redirected = false
|
||||||
|
|
||||||
$window.location.href = prefix + "/a"
|
$window.location.href = prefix + "/a"
|
||||||
|
|
@ -496,11 +520,11 @@ o.spec("route", function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(redirected).equals(true)
|
o(redirected).equals(true)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("the previous view redraws while onmatch resolution is pending (#1268)", function(done) {
|
o("the previous view redraws while onmatch resolution is pending (#1268)", function(done) {
|
||||||
|
|
@ -520,7 +544,7 @@ o.spec("route", function() {
|
||||||
|
|
||||||
route.set("/b")
|
route.set("/b")
|
||||||
|
|
||||||
setTimeout(function(){
|
callAsync(function() {
|
||||||
o(view.callCount).equals(1)
|
o(view.callCount).equals(1)
|
||||||
o(onmatch.callCount).equals(1)
|
o(onmatch.callCount).equals(1)
|
||||||
|
|
||||||
|
|
@ -530,12 +554,12 @@ o.spec("route", function() {
|
||||||
o(onmatch.callCount).equals(1)
|
o(onmatch.callCount).equals(1)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("m.route.set(m.route.get()) re-runs the resolution logic (#1180)", function(done){
|
o("m.route.set(m.route.get()) re-runs the resolution logic (#1180)", function(done){
|
||||||
var onmatch = o.spy()
|
var onmatch = o.spy()
|
||||||
var render = o.spy(function(){return m("div")})
|
var render = o.spy(function() {return m("div")})
|
||||||
|
|
||||||
$window.location.href = prefix + "/"
|
$window.location.href = prefix + "/"
|
||||||
route(root, '/', {
|
route(root, '/', {
|
||||||
|
|
@ -545,19 +569,21 @@ o.spec("route", function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(onmatch.callCount).equals(1)
|
o(onmatch.callCount).equals(1)
|
||||||
o(render.callCount).equals(1)
|
o(render.callCount).equals(1)
|
||||||
|
|
||||||
route.set(route.get())
|
route.set(route.get())
|
||||||
|
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(onmatch.callCount).equals(2)
|
callAsync(function() {
|
||||||
o(render.callCount).equals(2)
|
o(onmatch.callCount).equals(2)
|
||||||
|
o(render.callCount).equals(2)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("m.route.get() returns the last fully resolved route (#1276)", function(done){
|
o("m.route.get() returns the last fully resolved route (#1276)", function(done){
|
||||||
|
|
@ -577,10 +603,10 @@ o.spec("route", function() {
|
||||||
|
|
||||||
route.set("/2")
|
route.set("/2")
|
||||||
|
|
||||||
setTimeout(function(){
|
callAsync(function() {
|
||||||
o(route.get()).equals("/")
|
o(route.get()).equals("/")
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("routing with RouteResolver works more than once", function(done, timeout) {
|
o("routing with RouteResolver works more than once", function(done, timeout) {
|
||||||
|
|
@ -602,33 +628,35 @@ o.spec("route", function() {
|
||||||
|
|
||||||
route.set('/b')
|
route.set('/b')
|
||||||
|
|
||||||
setTimeout(function(){
|
callAsync(function() {
|
||||||
route.set('/a')
|
route.set('/a')
|
||||||
|
|
||||||
setTimeout(function(){
|
callAsync(function() {
|
||||||
o(root.firstChild.nodeName).equals("A")
|
o(root.firstChild.nodeName).equals("A")
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
}, FRAME_BUDGET)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("calling route.set invalidates pending onmatch resolution", function(done, timeout) {
|
o("calling route.set invalidates pending onmatch resolution", function(done) {
|
||||||
timeout(200)
|
|
||||||
|
|
||||||
var resolved
|
var resolved
|
||||||
$window.location.href = prefix + "/a"
|
$window.location.href = prefix + "/a"
|
||||||
route(root, "/a", {
|
route(root, "/a", {
|
||||||
"/a": {
|
"/a": {
|
||||||
onmatch: function() {
|
onmatch: function() {
|
||||||
return new Promise(function(resolve) {
|
return Promise.resolve(function(resolve) {
|
||||||
setTimeout(resolve, 20)
|
setTimeout(resolve, 0)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
render: function(vnode) {resolved = "a"}
|
render: function(vnode) {
|
||||||
|
resolved = "a"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"/b": {
|
"/b": {
|
||||||
view: function() {resolved = "b"}
|
view: function() {
|
||||||
|
resolved = "b"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -638,10 +666,10 @@ o.spec("route", function() {
|
||||||
o(resolved).equals("b")
|
o(resolved).equals("b")
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, 30)
|
}, 2) //FIXME magic number
|
||||||
})
|
})
|
||||||
|
|
||||||
o("route changes activate onbeforeremove", function(done, timeout) {
|
o("route changes activate onbeforeremove", function(done) {
|
||||||
var spy = o.spy()
|
var spy = o.spy()
|
||||||
|
|
||||||
$window.location.href = prefix + "/a"
|
$window.location.href = prefix + "/a"
|
||||||
|
|
@ -657,11 +685,11 @@ o.spec("route", function() {
|
||||||
|
|
||||||
route.set("/b")
|
route.set("/b")
|
||||||
|
|
||||||
setTimeout(function() {
|
callAsync(function() {
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, 30)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("throttles", function(done, timeout) {
|
o("throttles", function(done, timeout) {
|
||||||
|
|
@ -680,12 +708,12 @@ o.spec("route", function() {
|
||||||
redrawService.redraw()
|
redrawService.redraw()
|
||||||
var after = i
|
var after = i
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function() {
|
||||||
o(before).equals(1) // routes synchronously
|
o(before).equals(1) // routes synchronously
|
||||||
o(after).equals(2) // redraws synchronously
|
o(after).equals(2) // redraws synchronously
|
||||||
o(i).equals(3) // throttles rest
|
o(i).equals(3) // throttles rest
|
||||||
done()
|
done()
|
||||||
},40)
|
}, FRAME_BUDGET * 2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue