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

Sandbox.reset() no longer invokes resetHistory() on contained spies #1770

Closed
dpmott opened this issue Apr 30, 2018 · 3 comments
Closed

Sandbox.reset() no longer invokes resetHistory() on contained spies #1770

dpmott opened this issue Apr 30, 2018 · 3 comments

Comments

@dpmott
Copy link
Contributor

dpmott commented Apr 30, 2018

  • Sinon version : 5.0.1
  • Environment : Windows / Angular 4.4.6
  • Example URL :
  • Other libraries you are using:

What did you expect to happen?
I expect calls to sandbox.reset() to invoke spy.resetHistory() for spies in the collection.

What actually happens
Calls to sandbox.reset() invoke reset() on all fakes in its collection. Now that reset() has been removed from the spy API and no longer aliases resetHistory(), the spy history is no longer reset.

How to reproduce

    // in beforeAll:
    navigateSpy = sandbox.spy(TestBed.get(Router), 'navigate');
    // in afterEach:
    sandbox.reset();
    // in tests, cause a call to Router.navigate and then check spy call count

Related issue:
Issue #1712 is technically resolved with release 5.0.1, but it breaks the ability to reset the call count for spies contained within a sandbox when sandbox.reset() is called.

Proposed fix:
In lib\sinon\sandbox.js:
Change implementation of sandbox.reset to be:

    sandbox.reset = function reset() {
        this.resetHistory();
        this.resetBehavior();
    };

This matches the implementation in lib\sinon\stub.js

@mroderick
Copy link
Member

Thank you for your contribution to Sinon.JS. I have created a PR #1772 to address the issue.

@mroderick
Copy link
Member

The fix has been published to npm as sinon@5.0.2

@fatso83
Copy link
Contributor

fatso83 commented May 1, 2018

That was quick 👍

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
None yet
Projects
None yet
Development

No branches or pull requests

3 participants