mjackson / expect

Write better assertions
MIT License
2.29k stars 117 forks source link

Remove spy.reset #144

Open mjackson opened 8 years ago

mjackson commented 8 years ago

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.

ljharb commented 8 years ago

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.

mjackson commented 8 years ago

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.

ljharb commented 8 years ago

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 commented 8 years ago

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

mjackson commented 8 years ago

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.