sinonjs/sinon

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

Open

#2,471 opened on Sep 11, 2022

View on GitHub
 (3 comments) (0 reactions) (0 assignees)JavaScript (9,548 stars) (764 forks)batch import
Difficulty: EasyHelp wantedwontfix

Description

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

Contributor guide

sinon not throwing the error that been thrown when the error is undefined and also fail to assert · sinonjs/sinon#2471 | Good First Issue