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

Wrong example in Sandbox documentation #1788

Closed
kibertoad opened this issue May 10, 2018 · 4 comments
Closed

Wrong example in Sandbox documentation #1788

kibertoad opened this issue May 10, 2018 · 4 comments

Comments

@kibertoad
Copy link

  • Sinon version : 5.0.7

Documentation seems to be wrong. Here is a code snippet from http://sinonjs.org/releases/v5.0.7/sandbox/:

var sandbox = require('sinon').sandbox;
var myAPI = { hello: function () {} };

describe('myAPI.hello method', function () {

    beforeEach(function () {
        // stub out the `hello` method
        sandbox.stub(myAPI, 'hello');
    });

    afterEach(function () {
        // completely restore all fakes created through the sandbox
        sandbox.restore();
    });

This fails with "sandbox.stub is not a function" error.
Probably ".sandbox" in the first line should be replaced with "createSandbox();"?

@pgoldrbx
Copy link

pgoldrbx commented May 10, 2018

The sinon module exports a default sandbox instance.
https://github.com/sinonjs/sinon/blob/master/lib/sinon.js#L60

So really it would be var sandbox = require('sinon') or just var sinon = require('sinon') will the sandbox API methods available.

var foo = {
  bar: function () {}
};
sinon.stub(foo, 'bar');
sinon.restore();

So the docs will need a little reworking to explain this.

@fatso83
Copy link
Contributor

fatso83 commented May 11, 2018

@kibertoad You are correct. Would you mind try to update the doc sources with a PR?

@pgoldrbx It's correct that in recent Sinon versions it exports a default sandbox instance, but the Sandbox documentation should still explicitly mention how to create sandboxes and deal with them directly. The non-sandbox pieces can still refer to this section for details (once it is correct ...).

@kibertoad
Copy link
Author

@fatso83 Sure, will create a PR in the evening.

mroderick pushed a commit that referenced this issue May 12, 2018
@mroderick
Copy link
Member

This was fixed with #1792

franck-romano pushed a commit to franck-romano/sinon that referenced this issue Oct 1, 2019
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

No branches or pull requests

4 participants