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.resetHistory() does not reset history #2016

Closed
mcow opened this issue May 8, 2019 · 11 comments
Closed

sinon.resetHistory() does not reset history #2016

mcow opened this issue May 8, 2019 · 11 comments

Comments

@mcow
Copy link

mcow commented May 8, 2019

Per the docs:

Since sinon@5.0.0
You can reset history of all stubs using sinon.resetHistory()

To Reproduce

const assert = require('chai').assert;
const sinon = require('sinon');

describe('resetHistory', function() {
  var num = null;


  beforeEach(function() {
    num = sinon.createStubInstance(Number);
  });
  afterEach(() => {
    // Restore the default sandbox here
    sinon.restore();
  });

  describe('called on individual stub method', function() {
    it('should clear "called" status on stub', function() {
      num.toFixed();
      assert.isTrue(num.toFixed.called);
      num.toFixed.resetHistory();
      assert.isFalse(num.toFixed.called);
    });
  });

  describe('called on module', function() {
    it('should clear "called" status on all stubs', function() {
      num.toFixed();
      assert.isTrue(num.toFixed.called);
      sinon.resetHistory();
      assert.isFalse(num.toFixed.called);
    });
  });
});

RunKit demo

Actual results

Second test fails:
""called on module: should clear "called" status on all stubs: ❌. [assert.isFalse] Expected true to be false""

Expected results

All tests pass

@fatso83
Copy link
Contributor

fatso83 commented May 9, 2019

I updated the issue with the content of the zip file and also added it as a runnable RunKit demo, asserting that it works.

@rpgeeganage
Copy link
Contributor

I would like to help on bug fixing

@fatso83
Copy link
Contributor

fatso83 commented May 9, 2019

@rpgeeganage Please do! Here is our getting starting guide

@mcow
Copy link
Author

mcow commented May 9, 2019

I realize this comment is more of a feature request, but it would be nice if the "stub instance" object had its own resetHistory() (and resetBehavior() and reset()) methods, without needing to hit the entire sandbox.

@fatso83
Copy link
Contributor

fatso83 commented May 9, 2019

@mcow Have you tried? 😄 Stubs have had those features since version 2 of Sinon. The sandbox additions are much more recent.

@rpgeeganage
Copy link
Contributor

@fatso83 ,
Thanks a lot. I'll work on this.

@mcow
Copy link
Author

mcow commented May 9, 2019

@fatso83 Stub methods have that feature. "Stub instance" objects, the result of a createStubInstance() call (which lousy terminology is sinon's, don't blame me for the miscommunication) do not.

@rpgeeganage
Copy link
Contributor

@fatso83,
I have looked into the implementation of sinon.resetHistory and sinon.createStubInstance.
What I notice is, sinon.createStubInstance does not use the implementation from sandbox but sinon.resetHistory uses the implementation from sandbox. In sinon.resetHistory the collection is always empty. I'll dig deep.

@fatso83
Copy link
Contributor

fatso83 commented May 14, 2019

@mcow Aha, that explains things. I didn't notice the instance bit :) Hopefully @rpgeeganage deep dive comes up with something fruitful.

@brandonau24
Copy link
Contributor

@fatso83, should this issue be closed since the changes for it are merged into master?

@fatso83
Copy link
Contributor

fatso83 commented Jun 3, 2019

TG for astute observers 😄

@fatso83 fatso83 closed this as completed Jun 3, 2019
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

4 participants