Skip to content

Instantly share code, notes, and snippets.

@joelmukuthu
Last active August 8, 2016 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelmukuthu/155fe6734282f6366dfce66947ecb020 to your computer and use it in GitHub Desktop.
Save joelmukuthu/155fe6734282f6366dfce66947ecb020 to your computer and use it in GitHub Desktop.
This is a mocha test case demostrating a bug with [sinon.test](http://sinonjs.org/docs/#sinon-test) whereby the sandbox gets restored before a promise-based async test completes.
// sinon version 1.17.5
// Github issue: https://github.com/sinonjs/sinon/issues/1119
var sinon = require('sinon');
describe('sinon.test', function () {
describe('with a promise', function () {
it('does not restore the sandbox until the promise is fulfilled', sinon.test(function () {
var sandbox = this;
return Promise.resolve()
.then(function () {
var mySpy = sandbox.spy(); // TypeError: sandbox.spy is not a function
});
}));
});
describe('with a done callback', function () {
it('does not restore the sandbox until the callback is called', sinon.test(function (done) {
var sandbox = this;
Promise.resolve() // do something async
.then(function () {
var mySpy = sandbox.spy(); // okay
})
.then(done)
.catch(done);
}));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment