diff --git a/js/src/mopidy.js b/js/src/mopidy.js index b0cea67f..feea9790 100644 --- a/js/src/mopidy.js +++ b/js/src/mopidy.js @@ -255,11 +255,12 @@ Mopidy.prototype._getApiSpec = function () { Mopidy.prototype._createApi = function (methods) { var caller = function (method) { return function () { - var params = Array.prototype.slice.call(arguments); - return this._send({ - method: method, - params: params - }); + var message = {method: method}; + if (arguments.length === 0) { + return this._send(message); + } + message.params = Array.prototype.slice.call(arguments); + return this._send(message); }.bind(this); }.bind(this); diff --git a/js/test/mopidy-test.js b/js/test/mopidy-test.js index f46464cf..a735c4db 100644 --- a/js/test/mopidy-test.js +++ b/js/test/mopidy-test.js @@ -767,28 +767,36 @@ buster.testCase("Mopidy", { }, "by-position calling convention": { + setUp: function () { + this.mopidy._createApi({ + foo: { + params: ["bar", "baz"] + } + }); + this.sendStub = this.stub(this.mopidy, "_send"); + + }, + "is the default": function () { assert.equals( this.mopidy._settings.callingConvention, "by-position-only"); }, - "sends messages with function arguments unchanged": function () { - var sendStub = this.stub(this.mopidy, "_send"); - this.mopidy._createApi({ - foo: { - params: ["bar", "baz"] - } - }); + "sends no params if no arguments passed to function": function () { + this.mopidy.foo(); + assert.calledOnceWith(this.sendStub, {method: "foo"}); + }, + + "sends messages with function arguments unchanged": function () { this.mopidy.foo(31, 97); - assert.calledOnceWith(sendStub, { + assert.calledOnceWith(this.sendStub, { method: "foo", params: [31, 97] }); }, } - } });