Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create env.unspy #1289

Closed
wants to merge 14 commits into from
Closed

create env.unspy #1289

wants to merge 14 commits into from

Conversation

UziTech
Copy link
Contributor

@UziTech UziTech commented Mar 6, 2017

This will save the object and methodName or propertyName along with restoreObjectToOriginalState in the currentSpies array in the SpyRegistry.

A env.unspy method will allow the user to search the currentSpies array and execute the restoreObjectToOriginalState method for the object and methodName or propertyName provided

fixes #1281
fixes #236
fixes #342
fixes #683
fixes #975

execute restoreObjectToOriginalState on the method or property if it is a spy
If we spy on a method then replace it then spy on it again, we want the original method not the method the first spy was replaced with.
property descriptors are cloned
third time is the charm
@slackersoft
Copy link
Member

I'm not sure this is a feature that Jasmine needs right now. I would be happy to hear more discussion in #1281 about functionality that requires a user to remove a spy partway through a spec.

@mgol
Copy link

mgol commented Mar 15, 2017

I wonder, why:

clearSpy(thing, 'method');

instead of:

thing.method.clearSpy();

?

@UziTech
Copy link
Contributor Author

UziTech commented Mar 15, 2017

const spy = spyOn(thing, "method");
spy.clear();

would add another property (clear) that would be overwritten by the spy like calls and and do now.

plus having the opposite of spyOn(thing, "method") be unspy(thing, "method") seemed like it would be easier for people to remember the syntax.

@UziTech
Copy link
Contributor Author

UziTech commented Mar 15, 2017

i was debating on spyOff instead of unspy

maybe something to think about.

@mgol
Copy link

mgol commented Mar 15, 2017

In that case, spyOff sounds better as it refers directly to spyOn.

@UziTech
Copy link
Contributor Author

UziTech commented Mar 13, 2018

I'm going to close this as it seems to not be wanted by the maintainers.

If anyone wants this functionality I created an npm package jasmine-unspy that adds a method jasmine.unspy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to manually destroy a spy restore method for a spy Restore behavior for spy Spy Restore()
3 participants