forked from defunctzombie/away
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
66 lines (56 loc) · 1.23 KB
/
test.js
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
66
var assert = require('assert');
var idle = require('./');
var synth = require('synthetic-dom-events');
var move = function(element) {
var ev = synth('mousemove');
if (element.dispatchEvent) {
element.dispatchEvent(ev);
}
else {
element.fireEvent('onmousemove', ev);
}
};
test('create', function() {
var timer = idle(1000);
timer.stop();
});
test('idle', function(done) {
var timer = idle(1000);
var elapsed = false;
setTimeout(function() {
elapsed = true;
}, 900);
timer.on('idle', function() {
timer.stop();
assert.ok(elapsed);
done();
});
timer.on('active', function() {
assert.ok(false);
});
});
test('stop', function(done) {
var timer = idle(1000);
setTimeout(function() {
timer.stop();
}, 500);
setTimeout(function() {
done();
}, 1500);
timer.on('idle', function() {
assert.ok(false);
});
timer.on('active', function() {
assert.ok(false);
});
});
test('active', function(done) {
var timer = idle(1000);
timer.on('idle', function() {
move(document);
});
timer.on('active', function() {
timer.stop();
done();
});
});