more tests
This commit is contained in:
parent
a2c01d1d96
commit
e7420e72e1
14 changed files with 596 additions and 215 deletions
|
|
@ -26,6 +26,16 @@ o.spec("autoredraw", function() {
|
|||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
o("null renderer doesn't throw", function(done) {
|
||||
autoredraw(root, null, pubsub, spy)
|
||||
done()
|
||||
})
|
||||
|
||||
o("null pubsub doesn't throw", function(done) {
|
||||
autoredraw(root, renderer, null, spy)
|
||||
done()
|
||||
})
|
||||
|
||||
o("registers onevent", function() {
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
|
|
@ -45,6 +55,16 @@ o.spec("autoredraw", function() {
|
|||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
o("re-registering pubsub works", function() {
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
o("throttles", function(done) {
|
||||
var run = autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
|
|
@ -60,4 +80,16 @@ o.spec("autoredraw", function() {
|
|||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
o("does not redraw if e.redraw is false", function() {
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
renderer.render(root, {tag: "div", attrs: {onclick: function(e) {e.redraw = false}}})
|
||||
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
e.initEvent("click", true, true)
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
o(spy.callCount).equals(0)
|
||||
})
|
||||
|
||||
})
|
||||
|
|
@ -4,50 +4,72 @@ var o = require("../../ospec/ospec")
|
|||
var apiPubSub = require("../../api/pubsub")
|
||||
|
||||
o.spec("pubsub", function() {
|
||||
var pubsub
|
||||
var pubsub
|
||||
o.beforeEach(function() {
|
||||
pubsub = apiPubSub()
|
||||
})
|
||||
|
||||
o("it shouldn't error if there are no renderers", function() {
|
||||
pubsub.publish()
|
||||
})
|
||||
|
||||
o("it should run a single renderer entry", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
pubsub.subscribe(spy)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
pubsub.publish()
|
||||
pubsub.publish()
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(4)
|
||||
})
|
||||
|
||||
o("it should run all renderer entries", function() {
|
||||
var spy1 = o.spy()
|
||||
var spy2 = o.spy()
|
||||
var spy3 = o.spy()
|
||||
|
||||
pubsub.subscribe(spy1)
|
||||
pubsub.subscribe(spy2)
|
||||
pubsub.subscribe(spy3)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy1.callCount).equals(1)
|
||||
o(spy2.callCount).equals(1)
|
||||
o(spy3.callCount).equals(1)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy1.callCount).equals(2)
|
||||
o(spy2.callCount).equals(2)
|
||||
o(spy3.callCount).equals(2)
|
||||
})
|
||||
|
||||
o("shouldn't error if there are no renderers", function() {
|
||||
pubsub.publish()
|
||||
})
|
||||
|
||||
o("should run a single renderer entry", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
pubsub.subscribe(spy)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
pubsub.publish()
|
||||
pubsub.publish()
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(4)
|
||||
})
|
||||
|
||||
o("should run all renderer entries", function() {
|
||||
var spy1 = o.spy()
|
||||
var spy2 = o.spy()
|
||||
var spy3 = o.spy()
|
||||
|
||||
pubsub.subscribe(spy1)
|
||||
pubsub.subscribe(spy2)
|
||||
pubsub.subscribe(spy3)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy1.callCount).equals(1)
|
||||
o(spy2.callCount).equals(1)
|
||||
o(spy3.callCount).equals(1)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy1.callCount).equals(2)
|
||||
o(spy2.callCount).equals(2)
|
||||
o(spy3.callCount).equals(2)
|
||||
})
|
||||
|
||||
o("should stop running after unsubscribe", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
pubsub.subscribe(spy)
|
||||
pubsub.unsubscribe(spy)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(0)
|
||||
})
|
||||
|
||||
o("does nothing on invalid unsubscribe", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
pubsub.subscribe(spy)
|
||||
pubsub.unsubscribe(null)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue