Skip to content

Commit

Permalink
use slice to convert arguments object into an array
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinfarris committed Jul 23, 2019
1 parent ab92cf3 commit 8e00c22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/sinon/behavior.js
Expand Up @@ -8,7 +8,6 @@ var valueToString = require("@sinonjs/commons").valueToString;
var exportAsyncBehaviors = require("./util/core/export-async-behaviors");

var concat = arrayProto.concat;
var flat = arrayProto.flat;
var join = arrayProto.join;
var reverse = arrayProto.reverse;
var slice = arrayProto.slice;
Expand Down Expand Up @@ -176,8 +175,12 @@ var proto = {

return wrappedMethod.apply(context, args);
} else if (this.callsThroughWithNew) {
// Get the original method (assumed to be a constructor in this case)
var WrappedClass = this.effectiveWrappedMethod();
var F = WrappedClass.bind.apply(WrappedClass, concat([null], flat(args)));
// Turn the arguments object into a normal array
var argsArray = slice(args);
// Call the constructor
var F = WrappedClass.bind.apply(WrappedClass, concat([null], argsArray));
return new F();
} else if (typeof this.returnValue !== "undefined") {
return this.returnValue;
Expand Down
4 changes: 2 additions & 2 deletions test/stub-test.js
Expand Up @@ -3176,9 +3176,9 @@ describe("stub", function() {
propStub.withArgs("foo").returns({ foo: "bar" });
propStub.callThroughWithNew(propStub);

var result = new myObj.MyClass("not foo", "definitely not foo");
var result = new myObj.MyClass("not foo", ["definitely", "not", "foo"]);
assert.equals(callArgs[0], "not foo");
assert.equals(callArgs[1], "definitely not foo");
assert.equals(callArgs[1], ["definitely", "not", "foo"]);
assert.equals(result.foo, "baz");
});
});
Expand Down

0 comments on commit 8e00c22

Please sign in to comment.