Per the docs:
_Since [email protected]_
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);
});
});
});
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
I updated the issue with the content of the zip file and also added it as a runnable RunKit demo, asserting that it works.
I would like to help on bug fixing
@rpgeeganage Please do! Here is our getting starting guide
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.
@mcow Have you tried? 😄 Stubs have had those features since version 2 of Sinon. The sandbox additions are much more recent.
@fatso83 ,
Thanks a lot. I'll work on this.
@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.
@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.
@mcow Aha, that explains things. I didn't notice the _instance_ bit :) Hopefully @rpgeeganage deep dive comes up with something fruitful.
@fatso83, should this issue be closed since the changes for it are merged into master?
TG for astute observers 😄