diff --git a/lib/sinon/default-behaviors.js b/lib/sinon/default-behaviors.js index 86b44f1a3..b1dc0748b 100644 --- a/lib/sinon/default-behaviors.js +++ b/lib/sinon/default-behaviors.js @@ -31,6 +31,8 @@ function throwsException(fake, error, message) { var defaultBehaviors = { callsFake: function callsFake(fake, fn) { fake.fakeFn = fn; + fake.exception = undefined; + fake.exceptionCreator = undefined; }, callsArg: function callsArg(fake, index) { diff --git a/test/stub-test.js b/test/stub-test.js index eda1b39e9..15c07b2b4 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -1407,6 +1407,28 @@ describe("stub", function () { refute(fakeFn.called); assert(returned === 3); }); + + it("supersedes previous throws(error)", function () { + var fakeFn = createStub().returns(5); + this.stub = createStub(this.object, "method"); + + this.stub.throws(new Error("error")).callsFake(fakeFn); + var returned = this.object.method(1, 2); + + assert(fakeFn.called); + assert(returned === 5); + }); + + it("supersedes previous throws()", function () { + var fakeFn = createStub().returns(5); + this.stub = createStub(this.object, "method"); + + this.stub.throws().callsFake(fakeFn); + var returned = this.object.method(1, 2); + + assert(fakeFn.called); + assert(returned === 5); + }); }); describe(".objectMethod", function () {