forked from michaelrhodes/scroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
81 lines (63 loc) · 1.88 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var run = require('tape')
var ease = require('ease-component')
var scroll = require('./')
var container = document.createElement('div')
var box = document.createElement('div')
container.style.cssText = [
'height: 100px',
'outline: 1px solid #000',
'overflow: scroll',
'width: 100px'
].join(';')
box.style.cssText = [
'outline: 1px solid #888',
'height: 50px',
'width: 300px'
].join(';')
var n = 50
while (--n) {
container.appendChild(box.cloneNode(true))
}
document.body.appendChild(container)
run('it scrolls', function (test) {
container.scrollTop = 0
container.scrollLeft = 200
test.plan(3)
scroll.top(container, 200, function (error, position) {
test.ok(position === 200, 'it scrolled down 200 pixels')
scroll.top(container, 200, function (error, position) {
test.equal(error.message, 'Element already at target scroll position')
})
})
var leftOptions = { duration: 1000, ease: ease.inBounce }
scroll.left(container, -200, leftOptions, function (error, position) {
test.ok(position === 0, 'it scrolled across 200 pixels')
})
})
run('it can be cancelled', function (test) {
container.scrollTop = 0
container.scrollLeft = 200
test.plan(2)
var options = { duration: 1000, ease: ease.inBounce }
var cancel = scroll.left(container, -200, options,
function (error, position) {
test.ok(error, 'it produced an error')
test.equal(error.message, 'Scroll cancelled', 'it cancelled the animation')
})
setTimeout(cancel, 500)
})
run('callback fires after scroll events', function (test) {
container.scrollTop = 0
test.plan(1)
var okay = true
var done = false
container.addEventListener('scroll', function () {
if (done) okay = false
}, false)
scroll.top(container, 200, function () {
done = true
setTimeout(function () {
test.ok(okay, 'callback fired after scroll events')
}, 100)
})
})