diff --git a/lib/events.js b/lib/events.js index 9d2c262..b6be17a 100644 --- a/lib/events.js +++ b/lib/events.js @@ -48,10 +48,13 @@ function off (state, eventName, handler) { /** * trigger a specified event * - * @param {String} eventName Name of event + * @param {String} eventName Name of event + * @param {...*} [options] Options */ function trigger (state, eventName) { - state.emitter.emit(eventName) + var args = [].slice.call(arguments, 1) + + state.emitter.emit.apply(state.emitter, args) return this } diff --git a/tests/specs/events.js b/tests/specs/events.js index e9c210f..a9cdc45 100644 --- a/tests/specs/events.js +++ b/tests/specs/events.js @@ -129,3 +129,24 @@ test('"trigger" returns an object', function (t) { t.is(typeof hoodie.trigger('account:signin'), 'object', 'returns an object') }) + +test('"trigger" accepts optional arguments', function (t) { + t.plan(3) + + var hoodie = new Hoodie({ + PouchDB: PouchDBMock, + url: 'http://localhost:1234/hoodie' + }) + + var option1 = 'option1' + var option2 = 'option2' + var option3 = 'option3' + + hoodie.on('account:signin', function () { + t.equal(arguments[0], option1, 'receives the first argument') + t.equal(arguments[1], option2, 'receives the second argument') + t.equal(arguments[2], option3, 'receives the third argument') + }) + + hoodie.trigger('account:signin', option1, option2, option3) +})