diff --git a/src/constructors.js b/src/constructors.js index ccc9a59..fcab50b 100644 --- a/src/constructors.js +++ b/src/constructors.js @@ -2,7 +2,7 @@ var R = require('ramda') var fa = require('fluent-arguments') function getConstructorInstanceWithArgs (Constructor, constructorArgs) { - return new (Function.prototype.bind.apply(Constructor, arguments))() + return new (Function.prototype.bind.apply(Constructor, [ null ].concat(Array.prototype.slice.call(constructorArgs))))() } function getArrayFromArrayLikeObject (args) { diff --git a/test/index.spec.js b/test/index.spec.js index cfb12df..4da3d2a 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -35,6 +35,7 @@ beforeEach(function () { }) TestConstructor = function () { + this.args = Array.prototype.slice.call(arguments) this.field3 = function () { return 3 } this.field4 = sinon.stub() Object.defineProperty(this, 'getter', { get: function () { throw new Error('getter was evaluated') } }) @@ -133,6 +134,11 @@ describe('getSpyConstructor', function () { expect(spiedObject).to.be.an.instanceof(TestConstructor) }) + it('should create instances using the right arguments', function () { + var spiedObject = new SpyConstructor('Var 1', 2) + expect(spiedObject.args).to.deep.equal([ 'Var 1', 2 ]) + }) + it('should put spies on all methods', function () { var spiedObject = new SpyConstructor()