diff --git a/lib/sinon/behavior.js b/lib/sinon/behavior.js index 0f6e3864c..4fce7b3fb 100644 --- a/lib/sinon/behavior.js +++ b/lib/sinon/behavior.js @@ -137,7 +137,12 @@ }, invoke: function invoke(context, args) { - callCallback(this, args); + + if (this.callFakeFn) { + this.callFakeFn.apply(null, args); + } else { + callCallback(this, args); + } if (this.exception) { throw this.exception; @@ -170,7 +175,10 @@ throw new Error("Defining a stub by invoking \"stub.onCall(...).withArgs(...)\" is not supported. " + "Use \"stub.withArgs(...).onCall(...)\" to define sequential behavior for calls with certain arguments."); }, - + callsFake: function callsFake(fn) { + this.callFakeFn = fn; + return this; + }, callsArg: function callsArg(pos) { if (typeof pos != "number") { throw new TypeError("argument index is not number"); diff --git a/test/stub-test.js b/test/stub-test.js index debffa97c..29aa7a271 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -215,7 +215,19 @@ } } }, - + ".callsFake" : { + + setUp: function () { + this.stub = sinon.stub.create(); + }, + + "calls fake function" : function () { + var fake = sinon.stub.create(); + this.stub.callsFake(fake); + this.stub(1, 2); + assert(fake.calledWith(1, 2)); + } + }, ".callsArg": { setUp: function () { this.stub = sinon.stub.create();