diff --git a/src/constructors.js b/src/constructors.js index c6ca352..ccc9a59 100644 --- a/src/constructors.js +++ b/src/constructors.js @@ -10,7 +10,8 @@ function getArrayFromArrayLikeObject (args) { } var isMethod = R.curry(function (object, propName) { - return !Object.getOwnPropertyDescriptor(object, propName).get && typeof object[ propName ] === 'function' + return !Object.getOwnPropertyDescriptor(object, propName).get && + typeof object[ propName ] === 'function' && !(propName === 'constructor') }) var applyToEachFunctionKeyInObject = function (appliedFunction, object) { @@ -63,6 +64,8 @@ module.exports = function getStubOrSpyConstructor (getConstructorProperties) { return instance } + StubOrSpyConstructor.prototype = constructorProps.SourceConstructor.prototype + function configureMethods (methods) { methodParams = methods return this diff --git a/test/index.spec.js b/test/index.spec.js index a1f241c..cfb12df 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -128,6 +128,11 @@ describe('getSpyConstructor', function () { expect(spiedObject.proto2()).to.equal('p2') }) + it('should create instances of the original constructor', function () { + var spiedObject = new SpyConstructor() + expect(spiedObject).to.be.an.instanceof(TestConstructor) + }) + it('should put spies on all methods', function () { var spiedObject = new SpyConstructor() @@ -193,6 +198,11 @@ describe('getSpy- and getStubConstructor', function () { NewConstructor = testData.getConstructor(TestConstructor) }) + it('should create instances of itself', function () { + var instance = new NewConstructor() + expect(instance).to.be.an.instanceof(NewConstructor) + }) + describe('afterCreation', function () { it('should allow for manual post-processing before an instance is created', function () { NewConstructor.afterCreation(function (instance) {