diff --git a/src/pubsub.js b/src/pubsub.js index 3cec0a8..e021a2c 100755 --- a/src/pubsub.js +++ b/src/pubsub.js @@ -88,7 +88,7 @@ https://github.com/mroderick/PubSubJS while( position !== -1 ){ topic = topic.substr( 0, position ); position = topic.lastIndexOf('.'); - deliverMessage( message, topic, data ); + deliverMessage( message, topic, data, immediateExceptions ); } }; } diff --git a/test/test-publish.js b/test/test-publish.js index db00eb5..16b2fcf 100644 --- a/test/test-publish.js +++ b/test/test-publish.js @@ -160,6 +160,27 @@ delete PubSub.immediateExceptions; }, + "publish method should fail immediately on exceptions in namespaces when immediateExceptions is true" : function(){ + var func1 = function(){ + throw('some error'); + }, + spy1 = this.spy(); + + PubSub.subscribe( 'buy', func1 ); + PubSub.subscribe( 'buy', spy1 ); + + PubSub.immediateExceptions = true; + + assert.exception( function(){ + PubSub.publishSync( 'buy.tomatoes', 'some data' ); + }); + + refute( spy1.called ); + + // make sure we restore PubSub to it's original state + delete PubSub.immediateExceptions; + }, + "publish should call all subscribers, even when there are unsubscriptions within" : function(done){ var topic = TestHelper.getUniqueString(), spy1 = this.spy(),