-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
62 lines (49 loc) · 928 Bytes
/
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
'use strict';
import test from 'tape';
import Resize from './index';
const resize = new Resize();
test('resize emits event', function(t) {
t.plan(1);
let
called = 0,
i = 0;
resize.on(
'resize:start', () => {
called++;
}
);
resize.on(
'resize:end', () => {
called++;
}
);
setTimeout(function tick() {
if (++i < 10) {
fire();
setTimeout(tick, 10);
} else {
setTimeout(() => {
t.equal(called, 2);
t.end();
}, 500);
}
}, 10);
});
test('destroy', function(t) {
t.plan(0);
resize.on(
'resize:end', () => t.fail('resize:end wrongly dispatched')
);
resize.destroy();
fire();
t.end();
});
function fire() {
if (document.createEvent) {
var ev = document.createEvent('Event');
ev.initEvent('resize', true, true);
window.dispatchEvent(ev);
} else {
document.fireEvent('onresize');
}
}