Created
May 8, 2014 15:29
-
-
Save jgable/fd7fbd0516c849731404 to your computer and use it in GitHub Desktop.
Sinon Sandbox Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sinon = require('sinon'), | |
Widget = require('../../widget'); | |
describe('My widget', function () { | |
var sandbox; | |
beforeEach(function () { | |
// Create a sandbox for the test | |
sandbox = sinon.sandbox.create(); | |
}); | |
afterEach(function () { | |
// Restore all the things made through the sandbox | |
sandbox.restore(); | |
}); | |
it('is awesome', function () { | |
var widget = new Widget(); | |
// Make sure to only create stubs/spies through the sandbox | |
widget.fetch = sandbox.stub().returns({ one: 1, two: 2 }); | |
widget.loadData(); | |
expect(widget.fetch.called).to.be.true; | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I realise this is some real old code… but FWIW you don't need to create the sandbox each time, restore is putting it back to how it should be.