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

Improve documentation on Stubs #2062

Closed
michaelisvy opened this issue Jul 19, 2019 · 11 comments
Closed

Improve documentation on Stubs #2062

michaelisvy opened this issue Jul 19, 2019 · 11 comments
Labels

Comments

@michaelisvy
Copy link

michaelisvy commented Jul 19, 2019

Hi,
first of all I'd like to thank you for the great work on Sinon. I've been using it for a few weeks and it helps us a lot having better tests.
I would be happy to work on this issue if you're interested.

Is your feature request related to a problem? Please describe.
I was discussing with my colleagues about the fact that the sinon documentation is often not enough and that we need to search on the web / go on stackoverflow to get more examples before we can understand things.

Describe the solution you'd like
Have better examples for the stub documentation page. Add some examples that would be less theoretical, closer to what we use on a real project.
For instance, the example on stubs uses Spies (which will make people confused if they don't know what a Spy is).

I would be happy to draft something out if you are interested.

Describe alternatives you've considered
NA

Additional context
NA

@fatso83
Copy link
Contributor

fatso83 commented Jul 19, 2019

Improvements to our docs are welcome. We have been discussing a different take on the API docs as well, more in line with how the Lodash docs work, but that's a huge undertaking not likely to happen anytime soon. Working beats perfect :-)

For extensive tutorial-like examples, we do have the how-to section, which have been in need of expansion for some time.

@michaelisvy
Copy link
Author

thanks @fatso83 for the quick feedback. I see the example in the How to Section for stubs is pretty good. If that's ok for you, we will start by proposing a small contribution so we get used to the process (and you can see if that's suitable to your expectations).
I'll be working on it with my friend and colleague @lootster

@michaelisvy
Copy link
Author

michaelisvy commented Aug 7, 2019

hi, apology on the delay. I was playing with Sinon and will try to propose some changes by Friday night.
Edit: I found the answer to the below question, I've used an afterEach block.

Quick question: all the things I've tried with Sinon stubs work well, except in one case:
When using Sinon together with Jasmine, I understand that sinon.restore() should always be called before the expect() methods. Otherwise a failure to meet the expect() close will cause the next tests to fail.
However, it doesn't work when my stub throws an Error. I need to do expect() first and restore() after.

This is shown in the code samples I've created here: https://github.com/michaelisvy/javascript-samples/blob/master/src/test-doubles-sinon/stub/song-discount/songWithDiscountService.spec.js

Great thanks,
Michael.

@michaelisvy
Copy link
Author

hi @fatso83, I was looking at the code samples in the documentation. I realise that the code samples in the howto section are much better than the ones in the stubs documentation (that is, the stubs link in the documentation section).
However, the howto section is harder to find. Would it make sense to refactor the stubs documentation using some examples inspired from the howto section?
Also, on top of what is in the howto, we could add the following to the documentation:

  • show how to restore a stub
  • show how to throw an exception from a stub (and handle it)
  • show how to check that a stub has been called only once

Please let me know if that makes sense and I'll be happy to work on a pull request.

Regards,
Michael.

@michaelisvy
Copy link
Author

hi, I was just wondering if you had any feedback and if you're interested for me to work on a pull request :)

@fatso83
Copy link
Contributor

fatso83 commented Aug 29, 2019

Sure ... I'm a bit swamped with a new family situation and such, so I can't go into specifics on this, but I think there should be room for a kind of introduction to Sinon through various use cases, as you mentioned. But that already exists in many places, and we have linked to several, I believe. You can rip of the best parts and distill it into a PR.

@stale
Copy link

stale bot commented Oct 28, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 28, 2019
@michaelisvy
Copy link
Author

michaelisvy commented Oct 29, 2019 via email

@stale stale bot removed the stale label Oct 29, 2019
@michaelisvy
Copy link
Author

hello, we are preparing a pull request, thanks!

andrewdroz added a commit to andrewdroz/sinon that referenced this issue Nov 5, 2019
Proposed improvement to stubs doc, [as suggested here](sinonjs#2062).

- Focus more on the basics of stubbing an object's function (stub pre-programmed to throw exception/return value)
- Less discussion on spies
- Provide very simple code to test as an example, instead of external library's (PubSub) code
- Show why restoration of a stub is necessary
@andrewdroz andrewdroz mentioned this issue Nov 5, 2019
2 tasks
@stale
Copy link

stale bot commented Dec 28, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 28, 2019
@stale stale bot closed this as completed Jan 4, 2020
@mroderick mroderick reopened this Jan 5, 2020
@stale stale bot removed the stale label Jan 5, 2020
@fatso83
Copy link
Contributor

fatso83 commented Sep 10, 2024

This was fixed in #2152

@fatso83 fatso83 closed this as completed Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@mroderick @fatso83 @michaelisvy and others