Hi all,
How to manually delete/destroy a spy?
Example:
function signIn(done) {
...
// Fails the 2x time with "<spyOn> : bar has already been spied upon"
spyOn(foo, 'bar').and.callThrough();
...
expect(foo.bar).toHaveBeenCalledTimes(1);
}
function signOut(done) {
...
}
it('should be able to sign-in/sign-out multiple times', done => {
signIn(() => {
signOut(() => {
signIn(() => { // Fails with "<spyOn> : bar has already been spied upon"
done();
});
});
});
});
- Currently the second signIn call fails with "<spyOn> : bar has already been spied upon"
- I cannot make spyOn global otherwise error "Spies must be created in a before function or a spec"
So I would like to be able to write something like this:
function signIn(done) {
...
const spy = spyOn(foo, 'bar').and.callThrough();
...
expect(foo.bar).toHaveBeenCalledTimes(1);
spy.destroy();
}
Any idea?