Tests for m.redraw.sync()
This commit is contained in:
parent
ccb3d61675
commit
7de0124339
3 changed files with 87 additions and 1 deletions
|
|
@ -52,7 +52,7 @@ o.spec("mount", function() {
|
||||||
o(threw).equals(true)
|
o(threw).equals(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("renders into `root`", function() {
|
o("renders into `root` synchronoulsy", function() {
|
||||||
mount(root, createComponent({
|
mount(root, createComponent({
|
||||||
view : function() {
|
view : function() {
|
||||||
return m("div")
|
return m("div")
|
||||||
|
|
@ -74,6 +74,36 @@ o.spec("mount", function() {
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
o("Mounting a second root doesn't cause the first one to redraw", function() {
|
||||||
|
var view = o.spy(function() {
|
||||||
|
return m("div")
|
||||||
|
})
|
||||||
|
|
||||||
|
render(root, [
|
||||||
|
m("#child0"),
|
||||||
|
m("#child1")
|
||||||
|
])
|
||||||
|
|
||||||
|
mount(root.childNodes[0], createComponent({
|
||||||
|
view : view
|
||||||
|
}))
|
||||||
|
|
||||||
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
|
o(view.callCount).equals(1)
|
||||||
|
|
||||||
|
mount(root.childNodes[1], createComponent({
|
||||||
|
view : function() {
|
||||||
|
return m("div")
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
o(view.callCount).equals(1)
|
||||||
|
|
||||||
|
throttleMock.fire()
|
||||||
|
|
||||||
|
o(view.callCount).equals(1)
|
||||||
|
})
|
||||||
|
|
||||||
o("redraws on events", function() {
|
o("redraws on events", function() {
|
||||||
var onupdate = o.spy()
|
var onupdate = o.spy()
|
||||||
var oninit = o.spy()
|
var oninit = o.spy()
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,25 @@ o.spec("redrawService", function() {
|
||||||
}, 20)
|
}, 20)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
o("should stop running after unsubscribe, even if it occurs after redraw is requested", function(done) {
|
||||||
|
var spy = o.spy(function() {
|
||||||
|
throw new Error("This shouldn't have been called")
|
||||||
|
})
|
||||||
|
|
||||||
|
redrawService.subscribe(root, spy)
|
||||||
|
|
||||||
|
redrawService.redraw()
|
||||||
|
|
||||||
|
redrawService.unsubscribe(root, spy)
|
||||||
|
|
||||||
|
o(spy.callCount).equals(0)
|
||||||
|
setTimeout(function() {
|
||||||
|
o(spy.callCount).equals(0)
|
||||||
|
|
||||||
|
done()
|
||||||
|
}, 20)
|
||||||
|
})
|
||||||
|
|
||||||
o("does nothing on invalid unsubscribe", function(done) {
|
o("does nothing on invalid unsubscribe", function(done) {
|
||||||
var spy = o.spy()
|
var spy = o.spy()
|
||||||
|
|
||||||
|
|
@ -120,4 +139,33 @@ o.spec("redrawService", function() {
|
||||||
done()
|
done()
|
||||||
}, 20)
|
}, 20)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
o("redraw.sync() redraws all roots synchronously", function() {
|
||||||
|
var el1 = $document.createElement("div")
|
||||||
|
var el2 = $document.createElement("div")
|
||||||
|
var el3 = $document.createElement("div")
|
||||||
|
var spy1 = o.spy()
|
||||||
|
var spy2 = o.spy()
|
||||||
|
var spy3 = o.spy()
|
||||||
|
|
||||||
|
redrawService.subscribe(el1, spy1)
|
||||||
|
redrawService.subscribe(el2, spy2)
|
||||||
|
redrawService.subscribe(el3, spy3)
|
||||||
|
|
||||||
|
o(spy1.callCount).equals(0)
|
||||||
|
o(spy2.callCount).equals(0)
|
||||||
|
o(spy3.callCount).equals(0)
|
||||||
|
|
||||||
|
redrawService.redraw.sync()
|
||||||
|
|
||||||
|
o(spy1.callCount).equals(1)
|
||||||
|
o(spy2.callCount).equals(1)
|
||||||
|
o(spy3.callCount).equals(1)
|
||||||
|
|
||||||
|
redrawService.redraw.sync()
|
||||||
|
|
||||||
|
o(spy1.callCount).equals(2)
|
||||||
|
o(spy2.callCount).equals(2)
|
||||||
|
o(spy3.callCount).equals(2)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,14 @@ o.spec("api", function() {
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
}, FRAME_BUDGET)
|
||||||
})
|
})
|
||||||
|
o("sync", function() {
|
||||||
|
var root = window.document.createElement("div")
|
||||||
|
var view = o.spy()
|
||||||
|
m.mount(root, createComponent({view: view}))
|
||||||
|
o(view.callCount).equals(1)
|
||||||
|
m.redraw.sync()
|
||||||
|
o(view.callCount).equals(2)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue