Added tests for ChannelDefinition.publish

This commit is contained in:
Jim Cowart 2013-01-11 17:02:32 -05:00
parent fea0ddf952
commit 2cd58733d8
3 changed files with 31 additions and 18 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -13,4 +13,35 @@ describe( "ChannelDefinition", function () {
expect( sub instanceof SubscriptionDefinition ).to.be.ok();
} );
} );
describe( "When publishing from a channel definition", function(){
var channel, subscription;
beforeEach(function(){
channel = postal.channel("OhHai");
});
afterEach(function(){
postal.utils.reset();
channel = undefined;
subscription = undefined;
});
it( "Should allow a topic only to be used", function(){
subscription = channel.subscribe("topic.only", function(d, e) {
expect(typeof d === "undefined" ).to.be(true);
});
channel.publish("topic.only");
});
it( "Should allow a topic and data argument to be used", function(){
subscription = channel.subscribe("topic.and.data", function(d, e) {
expect(d).to.be("hai");
});
channel.publish("topic.and.data", "hai");
});
it( "Should allow an envelope argument to be used", function(){
subscription = channel.subscribe("envelope", function(d, e) {
expect( e.channel).to.be("OhHai");
expect( e.data).to.be("hai");
expect( e.foo).to.be("bar");
});
channel.publish({ topic: "envelope", data: "hai", foo: "bar" });
});
});
} );