Last active
August 8, 2016 09:41
-
-
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.
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
// 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