-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
101 lines (91 loc) · 2.59 KB
/
index.html
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!doctype html>
<html>
<head>
<script type="text/javascript" src="mocha.js"></script>
<script type="text/javascript" src="chai.js"></script>
<link rel="stylesheet" href="mocha.css">
</head>
<body>
<div id="mocha"></div>
<script>mocha.setup('bdd')</script>
<script src="mocha-asynculous.js"></script>
<script>
var expect = chai.expect;
describe('Asynculous', function() {
var callCount = 0;
function incrementCallCount() {
callCount++;
}
it('should work with single setTimeout', function() {
setTimeout(function() {
incrementCallCount();
expect(callCount).to.equal(1);
}, 50);
});
it('should work with setInterval', function() {
var counter = 0;
var interval = setInterval(function() {
counter++;
if (counter == 4) {
incrementCallCount();
expect(callCount).to.equal(2);
clearInterval(interval);
}
}, 50);
});
it('should work with double setTimeout', function() {
setTimeout(function() {
setTimeout(function() {
incrementCallCount();
expect(callCount).to.equal(3);
}, 140);
}, 50);
});
it('should work with clearTimeout', function() {
setTimeout(function() {
var timer = setTimeout(function() {
throw new Error('Timeout should have been cleared');
}, 140);
clearTimeout(timer);
incrementCallCount();
expect(callCount).to.equal(4);
}, 50);
});
it('should work with requestAnimationFrame', function() {
requestAnimationFrame(function() {
incrementCallCount();
expect(callCount).to.equal(5);
});
});
it('should work in sync mode', function() {
incrementCallCount();
expect(callCount).to.equal(6);
});
it('should be able to catch property events', function() {
var p = document.createElement('p');
document.body.appendChild(p);
p.onclick = function() {
incrementCallCount();
expect(callCount).to.equal(7);
}
p.dispatchEvent(new Event('click'));
});
it('should be able to catch addEventListener events', function() {
var p = document.createElement('p');
document.body.appendChild(p);
p.addEventListener('click', function() {
incrementCallCount();
expect(callCount).to.equal(8);
});
p.dispatchEvent(new Event('click'));
});
it('should have called all async operations', function() {
expect(callCount).to.equal(8);
});
});
</script>
<script>
mocha.run();
</script>
</body>
</html>