Skip to content
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

sinon not throwing the error that been thrown when the error is undefined and also fail to assert #2471

Open
rluvaton opened this issue Sep 11, 2022 · 3 comments

Comments

@rluvaton
Copy link
Contributor

rluvaton commented Sep 11, 2022

Describe the bug
If the function throw undefined then:

  1. calling the function does not throw
  2. sinon.assert.threw(a); fail

To Reproduce
ReplIt Link

const a = sinon.spy(() => {
  throw undefined;
});

try {
  a();
} catch (e) {
   // 1. this won't be logged
  console.log('Error has being thrown');
}

// 2. This will throw
// Uncaught AssertError: spy did not throw exception
sinon.assert.threw(a);

Expected behavior

  1. throw the thrown error
  2. the assertion should pass

As said in the docs about the 2nd thing:

sinon.assert.threw(spyOrSpyCall, exception);

Passes if spy threw the given exception.

The exception can be a String denoting its type, or an actual object.

If only one argument is provided, the assertion passes if spy ever threw any exception.

Context (please complete the following information):

  • Library version: 14.0.0
  • Environment: node
@rluvaton rluvaton changed the title sinon not throwing the error that been thrown when the error is undefined and fail to assert sinon not throwing the error that been thrown when the error is undefined and also fail to assert Sep 11, 2022
@fatso83
Copy link
Contributor

fatso83 commented Sep 12, 2022

So ... we should detect that a function has thrown, but if the exception is undefined, we should still regard it as thrown?

@rluvaton
Copy link
Contributor Author

yes, as the function being thrown should not be dependable on the value that was thrown

Copy link

stale bot commented Dec 27, 2023

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.

@stale stale bot added the wontfix label Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants