diff --git a/lib/sinon/default-behaviors.js b/lib/sinon/default-behaviors.js index 6f1fcadd7..1be5f9af1 100644 --- a/lib/sinon/default-behaviors.js +++ b/lib/sinon/default-behaviors.js @@ -15,7 +15,9 @@ function throwsException(fake, error, message) { fake.exceptionCreator = error; } else if (typeof error === "string") { fake.exceptionCreator = function () { - const newException = new Error(message || ""); + const newException = new Error( + message || `Sinon-provided ${error}` + ); newException.name = error; return newException; }; diff --git a/test/proxy-call-test.js b/test/proxy-call-test.js index 8cbec51ca..524d58f7f 100644 --- a/test/proxy-call-test.js +++ b/test/proxy-call-test.js @@ -1134,7 +1134,7 @@ describe("sinonSpy.call", function () { assert.equals( object.doIt.getCall(0).toString().replace(/ at.*/g, ""), - "doIt() !TypeError" + "doIt() !TypeError(Sinon-provided TypeError)" ); }); diff --git a/test/stub-test.js b/test/stub-test.js index 33dac0ef4..977a04120 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -940,6 +940,21 @@ describe("stub", function () { assert.contains(stub.firstCall.toString(), "not implemented"); }); + it("creates a non empty error message when error is a string and no message is passed", function () { + const stub = createStub(); + + stub.withArgs(1).throws("TypeError"); + + assert.exception( + function () { + stub(1); + }, + { + message: "Sinon-provided TypeError", + } + ); + }); + describe("lazy instantiation of exceptions", function () { let errorSpy; beforeEach(function () {