diff --git a/publication-collector.js b/publication-collector.js index a016630..a872983 100755 --- a/publication-collector.js +++ b/publication-collector.js @@ -27,9 +27,6 @@ PublicationCollector = class PublicationCollector extends EventEmitter { } collect(name, ...args) { - const handler = Meteor.server.publish_handlers[name]; - const result = handler.call(this, ...args); - if (_.isFunction(args[args.length - 1])) { const callback = args.pop(); this.on('ready', collections => { @@ -38,6 +35,9 @@ PublicationCollector = class PublicationCollector extends EventEmitter { }); } + const handler = Meteor.server.publish_handlers[name]; + const result = handler.call(this, ...args); + // TODO -- we should check that result has _publishCursor? What does _runHandler do? if (result) { // array-ize diff --git a/tests/publication-collector.test.js b/tests/publication-collector.test.js index 82ef2f2..501a385 100644 --- a/tests/publication-collector.test.js +++ b/tests/publication-collector.test.js @@ -109,6 +109,18 @@ describe('PublicationCollector', () => { collector.collect('publicationWithArgs', 'foo', 'bar'); }); + + it('should support optional publication arguments', (done) => { + Meteor.publish('publicationWithOptionalArg', function(arg1 = 'foo') { + assert.equal(arg1, 'foo'); + this.ready(); + done(); + }); + + const collector = new PublicationCollector(); + + collector.collect('publicationWithOptionalArg', function(){}); + }); }); describe('Added', () => {