Skip to content

Commit

Permalink
fix(Constructors): Change instance creation to be more compatible wit…
Browse files Browse the repository at this point in the history
…h Angular
  • Loading branch information
lukastaegert committed Jan 14, 2017
1 parent 198e77d commit 4ef6308
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/constructors.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
var R = require('ramda')
var fa = require('fluent-arguments')

function getConstructorInstanceWithArgs (Constructor, constructorArgs) {
return new (Function.prototype.bind.apply(Constructor, [ null ].concat(Array.prototype.slice.call(constructorArgs))))()
}

function getArrayFromArrayLikeObject (args) {
return Array.prototype.slice.call(args)
}
Expand Down Expand Up @@ -53,15 +49,15 @@ module.exports = function getStubOrSpyConstructor (getConstructorProperties) {
var afterCreation

function StubOrSpyConstructor () {
var instance = getConstructorInstanceWithArgs(constructorProps.SourceConstructor, arguments)
constructorProps.SourceConstructor.apply(this, arguments)
instanceArgs.push(getArrayFromArrayLikeObject(arguments))
instances.push(instance)
instances.push(this)

Target && applyToEachFunctionKeyInPrototypeChain(
constructorProps.processMethodOfInstance(instance), constructorProps.getInstanceMethodNameSource(instance))
methodParams.forEach(constructorProps.configureMethodOfInstance(instance))
afterCreation && afterCreation(instance)
return instance
constructorProps.processMethodOfInstance(this), constructorProps.getInstanceMethodNameSource(this))
methodParams.forEach(constructorProps.configureMethodOfInstance(this))
afterCreation && afterCreation(this)
return this
}

StubOrSpyConstructor.prototype = constructorProps.SourceConstructor.prototype
Expand Down

0 comments on commit 4ef6308

Please sign in to comment.