rename limiter to throttle and refactor
- don't inject raf/setTimeout since we can't really mock them w/ a good degree of timing accuracy anyways fix some unrelated tests
This commit is contained in:
parent
2af3aa27c7
commit
977239d207
15 changed files with 813 additions and 353 deletions
|
|
@ -2,29 +2,20 @@
|
|||
|
||||
var o = require("../../ospec/ospec")
|
||||
var domMock = require("../../test-utils/domMock")
|
||||
var async = require("./async")
|
||||
|
||||
var m = require("../../render/hyperscript")
|
||||
var createMounter = require("../mount")
|
||||
|
||||
o.spec("m.mount", function() {
|
||||
var FRAME_BUDGET = 1000 / 60
|
||||
var $window, root
|
||||
|
||||
o.beforeEach(function() {
|
||||
$window = domMock()
|
||||
async.setTimeout($window)
|
||||
root = $window.document.body
|
||||
})
|
||||
|
||||
o("is a function", function() {
|
||||
o(typeof createMounter).equals("function")
|
||||
})
|
||||
|
||||
o("returns a function after invocation", function() {
|
||||
o(typeof createMounter()).equals("function")
|
||||
})
|
||||
|
||||
o("updates passed in redraw object", function() {
|
||||
o("updates redraw object", function() {
|
||||
var redraw = {}
|
||||
var mount = createMounter($window, redraw)
|
||||
|
||||
|
|
@ -49,34 +40,7 @@ o.spec("m.mount", function() {
|
|||
o(root.firstChild.nodeName).equals("DIV")
|
||||
})
|
||||
|
||||
o("redraws on redraw.run()", function(done) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
var redraw = {}
|
||||
var mount = createMounter($window, redraw)
|
||||
|
||||
mount(root, {
|
||||
view : function() {
|
||||
return m("div", {
|
||||
oninit : oninit,
|
||||
onupdate : onupdate
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
|
||||
redraw.run()
|
||||
|
||||
// Wrapped to give time for the rate-limited redraw to fire
|
||||
setTimeout(function() {
|
||||
o(onupdate.callCount).equals(1)
|
||||
|
||||
done()
|
||||
}, 20)
|
||||
})
|
||||
|
||||
o("redraws on events", function(done, timeout) {
|
||||
o("redraws on events", function(done) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
var onclick = o.spy()
|
||||
|
|
@ -98,6 +62,7 @@ o.spec("m.mount", function() {
|
|||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
o(onupdate.callCount).equals(0)
|
||||
|
||||
o(onclick.callCount).equals(1)
|
||||
o(onclick.this).equals(root.firstChild)
|
||||
|
|
@ -109,6 +74,34 @@ o.spec("m.mount", function() {
|
|||
o(onupdate.callCount).equals(1)
|
||||
|
||||
done()
|
||||
}, 20)
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
o("redraws on redraw.run()", function(done) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
var redraw = {}
|
||||
var mount = createMounter($window, redraw)
|
||||
|
||||
mount(root, {
|
||||
view : function() {
|
||||
return m("div", {
|
||||
oninit : oninit,
|
||||
onupdate : onupdate
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
o(onupdate.callCount).equals(0)
|
||||
|
||||
redraw.run()
|
||||
|
||||
// Wrapped to give time for the rate-limited redraw to fire
|
||||
setTimeout(function() {
|
||||
o(onupdate.callCount).equals(1)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue