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.firstCall.returns() #105
Comments
Just use |
Kinda like, instead of
it'll be
Note: callback() would be a more complicated external function... (in my real code it's a database I could use a
Updated: To be honest I think my code just needs to be more testable :p but |
Hehe, I agree. I'm not so sure about |
i query facebook objects and need to follow each page in the results until nothing's left. the async i/o along with the iterative nature lends itself to a recursive call, i.e.
invoked like this
where it seems much easier to use a onCall() function vs trying to withArgs everything to get How would you suggest I refactor the code to be more testable? or is this is reasonable use case for something like onCall? |
I'm not quite sure how you should simplify it. You may be interested in the new matchers that's coming in Sinon 1.4 (already some information about them in the docs). They allow partial matching of object arguments. |
thanks for the reply. I did see matchers and ended up installing master at the time which gave me
|
I have a function that does a rock-paper-scissors battle. It needs to be called a few times. Having this kind of subsequent returns would be very useful (The Ruby mocking framework mocha does this). |
@Trevoke if you need more sophisticated stubbed behavior than returning a fixed value (or a value paired with some arguments), you could just do
|
Well, I can make this work, but it feels hackish (the solutions I will come up with for this particular problem certainly will be). I hesitate to request more behavior from sinon.js, as I do not grok Javascript yet. |
My stance is that this situation is pushing the limits of how clever you want your stubs and mocks to be. So you can escape the automatic stuff and provide your own function, or you can refactor to make the tests simpler :) |
You're probably right. On Thu, May 3, 2012 at 1:54 PM, Christian Johansen <
|
I also think "onCall().return()" might be very useful. I used them while working with phpUnit. I'd say the goal is the same as for 'withArgs()' - but applied to functions/methods that do not take any parameters.
where Have someone the way to do this with Sinon? |
There is an open issue with a long discussion about this feature here: #244 |
Thanks! |
Hi, I believe my old specs was too verbose and implementation specific. (Before every line I wrote hand an accompany unit test... I'm assuming this is not best practice?)
I'm trying a new way of doing things, is there something like
stub.firstCall.returns()
Thanks!
The text was updated successfully, but these errors were encountered: