-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
65 lines (56 loc) · 1.91 KB
/
test.js
File metadata and controls
65 lines (56 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
var startTimeout = require('./pauseable-timeout'),
chai = require('chai');
chai.should();
describe('pauseable-timeout', function () {
describe('setTimeout', function () {
it('should invoke callback in no less than 500 ms', function (done) {
var startTime = new Date().getTime();
startTimeout(function () {
(new Date().getTime() - startTime).should.be.at.least(500, 'callback invoked too soon');
done();
}, 500)
});
it('should invoke callback in no less than 750 ms when paused for 250 ms', function (done) {
var startTime = new Date().getTime();
var timeout = startTimeout(function () {
(new Date().getTime() - startTime).should.be.at.least(750, 'callback invoked too soon');
done();
}, 500)
timeout.pause();
setTimeout(function () {
timeout.resume();
}, 250);
});
it('should invoke callback in no less than 1000 ms when paused twice for 250 ms', function (done) {
var startTime = new Date().getTime();
var timeout = startTimeout(function () {
(new Date().getTime() - startTime).should.be.at.least(1000, 'callback invoked too soon');
done();
}, 500)
timeout.pause();
setTimeout(function () {
timeout.resume();
setTimeout(function () {
timeout.pause();
setTimeout(function () {
timeout.resume();
}, 250);
}, 250);
}, 250);
});
it('should invoke callback in no less than 500 ms with given arguments', function (done) {
var these = 'these',
are = 'are',
inputs = 'inputs';
var startTime = new Date().getTime();
startTimeout(function (arg1, arg2, arg3) {
(new Date().getTime() - startTime).should.be.at.least(500, 'callback invoked too soon');
arg1.should.equal(these, 'first argument is not "these"');
arg2.should.equal(are), 'second argument is not "are"';
arg3.should.equal(inputs, 'third argument is not "inputs"');
done();
}, 500, these, are, inputs);
});
});
});