-
-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.throws with no message creates error with empty message #2525
Comments
function throwsException(fake, error, message) {
if (typeof error === "function") {
fake.exceptionCreator = error;
} else if (typeof error === "string") {
fake.exceptionCreator = function () {
const newException = new Error(message || error || ""); // conditionally use error in case there is no message.
newException.name = error;
return newException;
};
} else if (!error) {
fake.exceptionCreator = function () {
return new Error("Error");
};
} else {
fake.exception = error;
}
} @mroderick as |
Hi, @mroderick, is this issue still open? I'd be happy to submit a PR with @ahmed1hsn's suggested changes if helpful. |
Please do. This is not really a breaking change AFAIK? More like a bug fix. |
Hi @fatso83, When I applied @ahmed1hsn's suggestion and ran
Should this test pass as originally expected? If not, let me know what the new expectation(s) should be. |
Not sure what a good message would be ... it looks a bit weird now. We can make it a bit more specific to tell the user Sinon made the error, just to give some value. Something like "Sinon-provided ${error}". What do you think? 🤔 |
Very well. That sounds fine for now! Pushed the suggested change here: |
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
When calling
throwsException
with aString
as theerror
argument and nomessage
argument, it will create errors with an empty message as seen in the code sample below.While this is not a bug as such, I do think it is poor design to return an Error instance with an empty
message
property.Instead, we could calculate a reasonable error message from the
error
argument.To Reproduce
Steps to reproduce:
Expected behavior
Non-empty
error.message
The text was updated successfully, but these errors were encountered: