sinonjs / sinonjs/sinon

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

Open
#2,471 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Difficulty: Easy Help wanted wontfix
Dominant language
JavaScript
Stars
9.8k
Forks
808
PR merge metrics
No merged PRs in 30d

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the JavaScript reproduction in the linked Replit example and trace how the spy records a thrown undefined value and how sinon.assert.threw checks it. Confirm both expected behaviors: the original call propagates the thrown value and the assertion passes when any exception was thrown.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.