Skip to content

Instantly share code, notes, and snippets.

@hokaccha
Last active December 16, 2015 09:19
Show Gist options
  • Save hokaccha/5412414 to your computer and use it in GitHub Desktop.
Save hokaccha/5412414 to your computer and use it in GitHub Desktop.
mocha.sinon = {
test: function(fn) {
var sandbox = sinon.sandbox.create();
if (fn.length >= 1) {
return function(done) {
fn.call(sandbox, function(err) {
done(err);
sandbox.restore();
});
};
}
else {
return function() {
fn.call(sandbox);
sandbox.restore();
};
}
}
};
describe('Foo', function() {
it('foo', mocha.sinon.test(function(done) {
this.stub(window, 'confirm').returns(true);
setTimeout(function() {
expect(window.confirm()).to.ok();
done();
}, 1000);
}));
it('bar', mocha.sinon.test(function() {
// confirm実行される(stubがリストアされてる)
expect(window.confirm()).to.ok();
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment