forked from sindresorhus/cycled
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
63 lines (52 loc) · 1.28 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
import test from 'ava';
import Cycled from '.';
const fixture = [1, 2, 3];
test('.current()', t => {
const c = new Cycled(fixture);
t.is(c.current(), 1);
c.next();
t.is(c.current(), 2);
});
test('.next()', t => {
const c = new Cycled(fixture);
t.deepEqual([c.next(), c.next(), c.next(), c.next()], [2, 3, 1, 2]);
});
test('.previous()', t => {
const c = new Cycled(fixture);
t.deepEqual([c.previous(), c.previous(), c.previous(), c.previous()], [3, 2, 1, 3]);
});
test('.step()', t => {
const c = new Cycled(fixture);
t.is(c.step(2), 3);
t.is(c.step(-2), 1);
});
test('.index', t => {
const c = new Cycled(fixture);
t.is(c.index, 0);
c.index = 2;
t.is(c.index, 2);
t.is(c.current(), 3);
c.index = -7;
t.is(c.index, 2);
t.is(c.current(), 3);
});
test('.indefinitely()', t => {
const c = new Cycled(fixture);
t.is(c.indefinitely().next().value, 2);
});
test('.indefinitelyReversed()', t => {
const c = new Cycled(fixture);
t.is(c.indefinitelyReversed().next().value, 3);
});
test('.indexOf()', t => {
const c = new Cycled(fixture);
t.is(c.indexOf(3), 2);
});
test('iterable', t => {
const c = new Cycled(fixture);
t.is(c[Symbol.iterator]().next().value, 2);
});
test('iterations on destructuring', t => {
const c = new Cycled(fixture);
t.deepEqual([...c], [2, 3, 1]);
});