expect icon indicating copy to clipboard operation
expect copied to clipboard

Remove spy.reset

Open mjackson opened this issue 9 years ago • 5 comments

The meaning of spy.reset is ambiguous (see discussion in #138). What exactly does it reset? The call count? The return/thrown values?

My vote is to either remove it or make its meaning more clear. If we remove it, the simple upgrade path is to substitute all uses of spy.reset() with spy.calls = []. Super easy.

mjackson avatar Jul 27 '16 18:07 mjackson

If it exists, it should reset everything - as in, it should be as if i created a brand-new spy and reassigned it to spy.

ljharb avatar Jul 27 '16 19:07 ljharb

Agree. Let's just get rid of it. I don't want to encourage people to keep spies around. They should be these quick, easy things you can just create and throw away.

mjackson avatar Jul 27 '16 19:07 mjackson

The main use case I can think of where it's really useful though is when doing require mocking (a la proxyquire) and you pass in a spy, that's then held in the require cache.

ljharb avatar Jul 27 '16 19:07 ljharb

ie, it can't be easily thrown away, so it's helpful to reset its state.

ljharb avatar Jul 27 '16 19:07 ljharb

It looks like proxyquire is using sinon for its spies implementation. Besides, seems like in the case you describe proxyquire would be creating incidental complexity and forcing me to handle it. Feels like a leaky abstraction.

mjackson avatar Jul 27 '16 19:07 mjackson