forked from vvo/in-viewport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hidden-parent-element.js
54 lines (47 loc) · 1.33 KB
/
hidden-parent-element.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
// this test checks that we have a
var supportsMutationObserver = typeof global.MutationObserver === 'function';
if (supportsMutationObserver) {
describe('asking if a div inside a hidden div is in the viewport', function() {
require('./fixtures/bootstrap.js');
beforeEach(h.clean);
afterEach(h.clean);
var visible = false;
var test;
var parent;
beforeEach(function() {
parent = h.createTest({
style: {
display: 'none',
width: '800px',
height: '800px'
}
});
test = h.createTest({
style: {
width: '500px',
height: '500px'
}
});
h.insertTest(test, parent);
h.insertTest(parent);
inViewport(test, function() {
visible = true;
});
});
// scrolling down and up, should not call the callback: parent is not visible
beforeEach(h.scroller(0, 100));
beforeEach(h.scroller(0, 0));
it('callback not called', function() {
assert(visible === false);
});
describe('when parent becomes visible, setInterval failsafe discovers the element', function(done) {
beforeEach(function(done) {
parent.style.display = 'block';
setTimeout(done, 200);
});
it('callback called', function() {
assert(visible === true);
});
});
});
}