Skip to content

Commit

Permalink
make tests more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianschmitt committed May 27, 2015
1 parent cf05307 commit ac70250
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global describe, it */
'use strict';

global.Promise = require('native-promise-only');
Expand All @@ -14,15 +15,21 @@ describe('sleepqueue', function() {
});

it('waits `interval` between callbacks', function() {
var queue = sleepqueue({ interval: 20 });
var queue = sleepqueue({ interval: 200 });
var then = Date.now();

queue.push(resolve());
queue.push(resolve());

return queue.push(resolve()).then(function() {
expect(Date.now() - then).to.be.within(40, 59);
});
return Promise.all([
queue.push(resolve()).then(expectDelay(0)),
queue.push(resolve()).then(expectDelay(200)),
queue.push(resolve()).then(expectDelay(400)),
queue.push(resolve()).then(expectDelay(600))
]);

function expectDelay(time) {
return function() {
expect(Date.now() - then).to.be.within(time, time + 100);
};
}
});

it('executes first callback immediately', function() {
Expand Down Expand Up @@ -92,7 +99,7 @@ describe('sleepqueue', function() {
return reject('test')().catch(function(){});
});

queue.once('error', function(err) { called = true; });
queue.once('error', function() { called = true; });

setTimeout(function() {
expect(called).to.equal(false);
Expand Down

0 comments on commit ac70250

Please sign in to comment.