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

First execution of a spy as a method renames that spy #950

Closed
glebec opened this issue Dec 14, 2015 · 4 comments · Fixed by #1435
Closed

First execution of a spy as a method renames that spy #950

glebec opened this issue Dec 14, 2015 · 4 comments · Fixed by #1435

Comments

@glebec
Copy link

glebec commented Dec 14, 2015

I find this quite bizarre. Is this intended behavior? It really conflicts with clear test output. Executing a spy as a method of an object renames that spy to the method name, but only once:

function bob () {}
var spy = sinon.spy(bob);
console.log(spy); // function bob

var obj = { methodName: spy };
console.log(spy); // function bob

spy();
console.log(spy); // function bob

obj.methodName.call(null);
console.log(spy); // function bob

obj.methodName();
console.log(spy); // function methodName

obj.otherProp = spy;
obj.otherProp();
console.log(spy); // function methodName
@mantoni
Copy link
Member

mantoni commented Dec 14, 2015

I guess it's trying to be more helpful in other use cases. I agree that it looks weird when used the way you describe it here. Not sure whether this should be seen as a bug or if it's a feature with this behavior as a trade off.

@glebec glebec changed the title Executing a spy stored as a method renames that spy First execution of a spy as a method renames that spy Dec 14, 2015
@glebec
Copy link
Author

glebec commented Dec 14, 2015

If that's the case, it doesn't go far enough since it only can be "renamed" this way once. And from a test-writer's perspective, it's very unhelpful if you are trying to sort out many similar spies which you have carefully given different names, but they are all getting renamed to a single property name because my code happens to store functions in wrapper objects and execute them as methods.

If this is indeed a feature and not a bug, I think it should be deprecated.

@mantoni
Copy link
Member

mantoni commented Dec 14, 2015

Would you be able to look at the Sinon sources and make a suggestion where to change it? I don't think anybody has "hard" dependencies on this, be it a bug or a feature - maybe there isn't even a specific intention behind it.

@glebec
Copy link
Author

glebec commented Dec 14, 2015

I can certainly go digging… not this week, but sometime.

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 a pull request may close this issue.

2 participants