Allow callThrough to call constructor functions without errors

This commit is contained in:
Elliot Nelson
2020-01-28 19:40:44 -05:00
parent 5e98ee951c
commit 9febe3159d
3 changed files with 56 additions and 30 deletions

View File

@@ -96,8 +96,15 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
* @since 2.0.0
* @function
*/
SpyStrategy.prototype.exec = function(context, args) {
return this.plan.apply(context, args);
SpyStrategy.prototype.exec = function(context, args, isConstructor) {
var list = [context].concat(args ? Array.prototype.slice.call(args) : []);
var target = this.plan.bind.apply(this.plan, list);
if (isConstructor) {
return new target();
} else {
return target();
}
};
/**