-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.js
96 lines (79 loc) · 2.3 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var animate = require('./')
var test = require('tape').test
test('a Promise wrapper around gsap / twenelite', function(t) {
t.test('Basic tests', function(st){
st.plan(4)
st.equal(animate, animate.to, 'animate equals animate.to')
var a = { value: 0 }
animate.to(a, 0.5, {
value: 1.0
}).then(function() {
st.equal(a.value, 1, 'animate.to works')
})
var b = { value: 5 }
animate.set(b, { delay: 0.5, value: 10 }).then(function() {
st.equal(b.value, 10, 'animate.set with delay works')
})
var c = { value: 10 }
animate.fromTo(c, 1.0, { value: 0 }, { value: 5 }).then(function() {
st.equal(c.value, 5, 'animate.fromTo works')
})
});
t.test('From to tests', function(st){
st.plan(1);
var d = {value: 0};
var promise = animate
.fromTo(d, 1, { value: 0 }, { value: 100 })
.finally(function () {
st.assert(d.value < 100, 'fromTo cancelling works')
});
setTimeout(function(){
promise.cancel()
}, 200);
});
t.test('StaggerFrom tests', function(st){
st.plan(1);
var e = [{value: 100}, {value: 100}, {value: 100}]
var promise = animate
.staggerFrom(e, 1, { value: 0 }, 0.1)
.finally(function () {
st.assert(e.slice(-1)[0].value < 100, 'staggerFrom cancelling works')
});
setTimeout(function(){
promise.cancel()
}, 200);
});
t.test('Stagger FromTo tests', function(st){
st.plan(1);
var e = [{value: 100}, {value: 100}, {value: 100}]
var promise = animate
.staggerFromTo(e, 1, { value: 0 }, { value: 100 }, 0.1)
.finally(function () {
st.assert(e.slice(-1)[0].value < 100, 'staggerFromTo cancelling works')
});
setTimeout(function(){
promise.cancel()
}, 200);
});
t.test('Promise all', function(st){
st.plan(1);
var f = [{value: 0}, {value: 0}, {value: 0}, {value: 0}, {value: 0}, {value: 0}];
var to = {value: 100};
var timeout = setTimeout(function () {
st.fail('not all promises resolved, are arguments being mutated?')
}, 800)
Promise.all([
animate.set(f[0], to),
animate.set(f[1], to),
animate.to(f[2], 0.5, to),
animate.to(f[3], 0.5, to),
animate.fromTo(f[4], 0.5, {value: 0}, to),
animate.fromTo(f[5], 0.5, {value: 0}, to)
]).then(function () {
clearTimeout(timeout)
st.assert(f.every(function (item) {
return item.value === to.value
}), 'all promises resolved')
})
});
})