Skip to content

Commit

Permalink
Test for #43
Browse files Browse the repository at this point in the history
Assert that all subscribers are called, even if some are unsubscribed during publishing
  • Loading branch information
mroderick committed Feb 11, 2014
1 parent 19d2ba3 commit 751b0c4
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion test/test-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,35 @@

// 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(),
func1 = function func1(){
PubSub.unsubscribe(func1);
spy1();
},

spy2 = this.spy(),
func2 = function func2(){
PubSub.unsubscribe(func2);
spy2();
},

clock = this.useFakeTimers();

PubSub.subscribe(topic, func1);
PubSub.subscribe(topic, func2);

PubSub.publish(topic, 'some data');
clock.tick(1);

assert(spy1.called, 'expected spy1 to be called');
assert(spy2.called, 'expected spy2 to be called');

clock.restore();
done();
}
});

}(this));

0 comments on commit 751b0c4

Please sign in to comment.