testdouble.js icon indicating copy to clipboard operation
testdouble.js copied to clipboard

Feature request: `td.func().reset()` (reset spy/stub state)

Open JakobJingleheimer opened this issue 11 months ago • 0 comments

In many cases, spies are re-useable, so they can be set up at the root of the test.

When asserting cases where a spy may or may not have been called, the spy's state needs to be re-set between cases (via afterEach).

At current, it seems the only way to effectively re-set a testdouble spy/stub's state is to overwrite the whole thing with a fresh spy, which creates a daisy-chain of make-work: that spy is likely being fed into a module replacement, so now the module has to be needlessly replaced every time the spy/stub is re-set.

JakobJingleheimer avatar Mar 20 '24 13:03 JakobJingleheimer