Skip to content

Commit

Permalink
improved tests for replaced globals
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Jun 10, 2016
1 parent 5de5d42 commit 53fdf64
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions test.js
Expand Up @@ -65,27 +65,43 @@ function test (ourProcess) {
});

describe('rename globals', function (t) {
it('throws an error', function (done){
var oldTimeout = setTimeout;
var oldClear = clearTimeout;
function cleanUp() {
setTimeout = oldTimeout;
clearTimeout = oldClear;
var oldTimeout = setTimeout;
var oldClear = clearTimeout;

it('clearTimeout', function (done){

var ok = true;
clearTimeout = function () {
ok = false;
}
ourProcess.nextTick(function () {
setTimeout(function () {
clearTimeout = oldClear;
var err;
try {
assert.ok(ok, 'fake clearTimeout ran');
} catch (e) {
err = e;
}
done(err);
}, 50);
});
});
it('just setTimeout', function (done){


setTimeout = function () {
cleanUp();
assert.ok(false);
done();
}
setTimeout = oldTimeout;
try {
assert.ok(false, 'fake setTimeout called')
} catch (e) {
done(e);
}

clearTimeout = function () {
cleanUp();
assert.ok(false);
done();
}

ourProcess.nextTick(function () {
cleanUp();
assert.ok(true);
setTimeout = oldTimeout;
done();
});
});
Expand Down

0 comments on commit 53fdf64

Please sign in to comment.