-
-
Notifications
You must be signed in to change notification settings - Fork 772
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
Stub/Spies direct onto an Object #87
Comments
your problem is related to how your subject.js module gets a reference to the exports of module.js. subject.js gets a direct reference to the exports of module.js rather than a reference to the spy that you create based on the exports of that module. when you export an object, subject.js gets a reference to that object but when it tries to access a property of that object, you've already replaced the original function attached to that property with the spy function - this is why it works when you export an object. your problem is not so much related to what you can or cannot spy on but rather it is a problem of what your subject.js gets a reference to when it loads. there's probably a clearer explanation but maybe that helps you see what's happening. |
As far as I can tell, there is no way to implement stubbing of functions that are directly exported (e.g |
why can't exporting a function reference work? it's perfectly valid JS and works in node. this is valid: var myObject = function () {}; |
@rschiavi the issue is not whether or not it's valid. the problem is that there's no way to get hold of the |
What about when you define your export like this: module.js subject.js test_subject.js module is exporting an object, not a function directly. The error message I get is: ) subject should call x(): |
@kris-at-tout You want to do:
And:
That is, you stub the |
Hi, I'm new to BDD/TDD, Sinon.js is great btw :)
I'm using Sinon.js with Mocha & Node.js, and I was wondering if there was a way to add spies/stubs onto existing objects... so that any reference to that object now includes those spies... for example...
module.js
subject.js
test_subject.js
might not be possible, thanks :)
just wanted to note that if module.js returns an object, it'll be spyable...
related question for me, if X was instead a class, would it be possible? For example
My understanding of how instances are created might be completely wrong. But is it correct that there is no way to turn an object into a spy, but instead have to create a new object, that's a spy? For example:
Thank you :)
The text was updated successfully, but these errors were encountered: