-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean up 'debug' logic in pubsub. add tests for pubsub. Element shoul…
…d have width=100% if not specified.
- Loading branch information
1 parent
892e883
commit 7878fa5
Showing
7 changed files
with
105 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import * as pubsub from '../src/components/lib/pubsub.js'; | ||
const PrivateMessageBus = pubsub.PrivateMessageBus; | ||
const PubSub = pubsub.PubSub; | ||
|
||
describe( "PubSub Module", () => { | ||
it("should have a global bus", ()=>{ | ||
PubSub.global.publish.should.be.a.Function; | ||
PubSub.global.subscribe.should.be.a.Function; | ||
PubSub.global.last.should.be.a.Function; | ||
PubSub.global.clearLast.should.be.a.Function; | ||
PubSub.global.clearAllCallbacks.should.be.a.Function; | ||
PubSub.global.clearTopicCallbacks.should.be.a.Function; | ||
}); | ||
it("should have local busses, bound to html elements", ()=>{ | ||
var elem = document.createElement("div"); | ||
var bus = new PrivateMessageBus(elem); | ||
bus.should.be.an.instanceOf(PrivateMessageBus); | ||
}); | ||
it("should implement a private message bus bound to an HTML element", ()=>{ | ||
var elem = document.createElement("div"); | ||
new PrivateMessageBus(elem); | ||
var privateTestValue = null; | ||
PubSub.subscribe("test", (value)=>{ privateTestValue = value; }, elem) | ||
PubSub.publish("test", "value", elem); | ||
(String(privateTestValue)).should.equal("value"); | ||
}); | ||
it("should allow users to supply a 'debug' parameter when instantiating the bus", ()=>{ | ||
var oldDebug = console.debug; | ||
var called = false; | ||
console.debug = function(){ called = true; oldDebug.apply(console, arguments); } | ||
var elem = document.createElement("div"); | ||
new PrivateMessageBus(elem, true); | ||
PubSub.publish("test", "value", elem); | ||
called.should.equal(true); | ||
console.debug = oldDebug; | ||
}); | ||
it("should users to set a 'debug' attribute on the global bus", ()=>{ | ||
var oldDebug = console.debug; | ||
var called = false; | ||
console.debug = function(){ called = true; oldDebug.apply(console, arguments); } | ||
PubSub.global.setDebug(true); | ||
PubSub.global.publish("test", "value"); | ||
called.should.equal(true); | ||
console.debug = oldDebug; | ||
}); | ||
it("should implement a global message bus in the module scope", ()=>{ | ||
var globalTestValue = null; | ||
PubSub.global.subscribe("test", (value)=>{ globalTestValue = value; }) | ||
PubSub.publish("test", "value"); | ||
(String(globalTestValue)).should.equal("value"); | ||
}); | ||
it("should not 'hear' local bus events on the global bus", ()=>{ | ||
var elem = document.createElement("div"); | ||
new PrivateMessageBus(elem, true); | ||
var privateTestValue = null; | ||
var globalTestValue = null; | ||
PubSub.subscribe("test", (value)=>{ privateTestValue = value; }, elem) | ||
PubSub.global.subscribe("test", (value)=>{ globalTestValue = value; }) | ||
PubSub.publish("test", "value", elem); | ||
(String(privateTestValue)).should.equal("value"); | ||
(String(globalTestValue)).should.equal("null"); | ||
}); | ||
it("should not 'hear' global bus events on the local bus", ()=>{ | ||
var elem = document.createElement("div"); | ||
new PrivateMessageBus(elem, true); | ||
var privateTestValue = null; | ||
var globalTestValue = null; | ||
PubSub.subscribe("test", (value)=>{ privateTestValue = value; }, elem) | ||
PubSub.global.subscribe("test", (value)=>{ globalTestValue = value; }) | ||
PubSub.global.publish("test", "value"); | ||
(String(privateTestValue)).should.equal("null"); | ||
(String(globalTestValue)).should.equal("value"); | ||
}); | ||
}) |