sinon
sinon copied to clipboard
sinon not throwing the error that been thrown when the error is undefined and also fail to assert
Describe the bug
If the function throw undefined
then:
- calling the function does not throw
-
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
- throw the thrown error
- 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
So ... we should detect that a function has thrown, but if the exception is undefined, we should still regard it as thrown?
yes, as the function being thrown should not be dependable on the value that was thrown
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.