diff --git a/src/pubsub.js b/src/pubsub.js index 8c3c538..16e1730 100644 --- a/src/pubsub.js +++ b/src/pubsub.js @@ -251,10 +251,15 @@ */ PubSub.countSubscriptions = function countSubscriptions(topic){ var m; + // eslint-disable-next-line no-unused-vars + var token; var count = 0; - for (m in messages){ - if (Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0){ - count++; + for (m in messages) { + if (Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0) { + for (token in messages[m]) { + count++; + } + break; } } return count; diff --git a/test/test-countSubscriptions.js b/test/test-countSubscriptions.js index 5766455..5dac3ab 100644 --- a/test/test-countSubscriptions.js +++ b/test/test-countSubscriptions.js @@ -16,4 +16,17 @@ describe('test-countSubscriptions method', function () { assert.equals(counts,1); }); + + it('should count all subscriptions', function() { + var topic = TestHelper.getUniqueString(), + spy1 = sinon.spy(), + spy2 = sinon.spy(); + + PubSub.subscribe(topic, spy1); + PubSub.subscribe(topic, spy2); + + var counts = PubSub.countSubscriptions(topic); + + assert.equals(counts, 2); + }); });