js: Don't include params if method is called without arguments
This commit is contained in:
parent
858a6977df
commit
149287c06a
@ -255,11 +255,12 @@ Mopidy.prototype._getApiSpec = function () {
|
|||||||
Mopidy.prototype._createApi = function (methods) {
|
Mopidy.prototype._createApi = function (methods) {
|
||||||
var caller = function (method) {
|
var caller = function (method) {
|
||||||
return function () {
|
return function () {
|
||||||
var params = Array.prototype.slice.call(arguments);
|
var message = {method: method};
|
||||||
return this._send({
|
if (arguments.length === 0) {
|
||||||
method: method,
|
return this._send(message);
|
||||||
params: params
|
}
|
||||||
});
|
message.params = Array.prototype.slice.call(arguments);
|
||||||
|
return this._send(message);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
|||||||
@ -767,28 +767,36 @@ buster.testCase("Mopidy", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
"by-position calling convention": {
|
"by-position calling convention": {
|
||||||
|
setUp: function () {
|
||||||
|
this.mopidy._createApi({
|
||||||
|
foo: {
|
||||||
|
params: ["bar", "baz"]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.sendStub = this.stub(this.mopidy, "_send");
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
"is the default": function () {
|
"is the default": function () {
|
||||||
assert.equals(
|
assert.equals(
|
||||||
this.mopidy._settings.callingConvention,
|
this.mopidy._settings.callingConvention,
|
||||||
"by-position-only");
|
"by-position-only");
|
||||||
},
|
},
|
||||||
|
|
||||||
"sends messages with function arguments unchanged": function () {
|
"sends no params if no arguments passed to function": function () {
|
||||||
var sendStub = this.stub(this.mopidy, "_send");
|
this.mopidy.foo();
|
||||||
this.mopidy._createApi({
|
|
||||||
foo: {
|
|
||||||
params: ["bar", "baz"]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
assert.calledOnceWith(this.sendStub, {method: "foo"});
|
||||||
|
},
|
||||||
|
|
||||||
|
"sends messages with function arguments unchanged": function () {
|
||||||
this.mopidy.foo(31, 97);
|
this.mopidy.foo(31, 97);
|
||||||
|
|
||||||
assert.calledOnceWith(sendStub, {
|
assert.calledOnceWith(this.sendStub, {
|
||||||
method: "foo",
|
method: "foo",
|
||||||
params: [31, 97]
|
params: [31, 97]
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user