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

.throws() in conjuction with .onFirstCall() doesn't work #1526

Closed
RiddleMan opened this issue Aug 11, 2017 · 5 comments
Closed

.throws() in conjuction with .onFirstCall() doesn't work #1526

RiddleMan opened this issue Aug 11, 2017 · 5 comments
Labels

Comments

@RiddleMan
Copy link

RiddleMan commented Aug 11, 2017

Hi,

After upgrade to Sinon 3.2.0, I've spotted that some of my tests are failing.
As a result of a quick investigation, I've found that .throws() is not throwing when it's used together with .onFirstCall(), onCall() etc.

I've checked this issue for .withArgs() and it seems to work correctly.

  • Sinon version : 3.2.0
  • Environment : nodejs
  • Example URL :
  • Other libraries you are using:

What did you expect to happen?
It should throw an Error only on the first call or no of the call specified in the .onCall() method.
What actually happens
It doesn't throw any error.
How to reproduce

  const stub = sinon.stub();
  stub
    .onFirstCall()
    .throws();

  try {
    stub();
    console.log('WRONG');
  } catch(e) {
    console.log('OK');
  }
@fatso83
Copy link
Contributor

fatso83 commented Aug 12, 2017

Not reproducible.

npm install [email protected]
[email protected] /tmp/foo
└─┬ [email protected] 
  ├── [email protected] 
  ├── [email protected] 
  ├── [email protected] 
  ├── [email protected] 
  ├─┬ [email protected] 
  │ ├── [email protected] 
  │ └── [email protected] 
  ├── [email protected] 
  ├── [email protected] 
  ├── [email protected] 
  └── [email protected] 

npm WARN [email protected] No description
npm WARN [email protected] No repository field.

developer at developer-XPS-13-9360 in /tmp/foo 
$ node test.js
OK

test.js

var sinon = require('sinon')
const stub = sinon.stub();

stub.onFirstCall()
    .throws();

try {
    stub();
    throw "wrong"
} catch(e) {
    console.log('OK');
}

@fatso83 fatso83 closed this as completed Aug 12, 2017
@RiddleMan
Copy link
Author

I've made the same environment like yours, and I'm still getting the same problem.
If it will help I'm running on OS X, Node 8.3.0.

I'm also able to reproduce that inside of the browser (Chrome)
Here's the link to JSBin which causes that problem.

http://jsbin.com/vihebikone/edit?js,console

@fatso83
Copy link
Contributor

fatso83 commented Aug 14, 2017

I'm an idiot (examine my test above). Reopening.

@fatso83 fatso83 reopened this Aug 14, 2017
@RiddleMan
Copy link
Author

Yeah! It makes sense ;) But at the first look I didn't spot anything wrong 😁

fatso83 added a commit to fatso83/git-bisect-scripts that referenced this issue Aug 14, 2017
@fatso83
Copy link
Contributor

fatso83 commented Aug 14, 2017

Created a test case suitable for git bisect and found the offending commit in #1511:

git bisect bad master                                                                                                                                                                                
git bisect good v2.0.0                                                                                                                                                                               
git bisect run ../git-bisect-scripts/sinon-1526.sh                                                                                                                                                   
# ... lots of output                                                                                                                                                                                               
ec74e944173e53fd71afa19e073f1262448534b9 is the first bad commit    

@fatso83 fatso83 added the Bug label Aug 14, 2017
noisecapella pushed a commit to noisecapella/sinon that referenced this issue Aug 14, 2017
fatso83 added a commit that referenced this issue Aug 14, 2017
Fix regression for issue #1526 regarding onFirstCall().throws()
franck-romano pushed a commit to franck-romano/sinon that referenced this issue Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants