unexpected-sinon
unexpected-sinon copied to clipboard
to have calls satisfying <function>: Error when a spy that isn't mentioned is called by the function
I once did something like this:
var spy1 = sinon.spy().named('spy1');
spy1(123);
var spy2 = sinon.spy().named('spy2');
expect([spy1], 'to have calls satisfying', function () {
spy1(123);
spy2(456);
});
... which currently passes because the assertion is only tracking the spies that are passed as the subject.
Unfortunately there's no easy way to detect the spy2(456); call as there's no useful require('sinon').spy().__proto__ or similar to snoop into, and sinon doesn't keep track of all the spies it has created, except when using a sandbox (https://github.com/unexpectedjs/unexpected-sinon/issues/15).
Ideas are very welcome :)