-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest.js
More file actions
34 lines (30 loc) · 813 Bytes
/
test.js
File metadata and controls
34 lines (30 loc) · 813 Bytes
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
import test from 'ava';
import negativeArray from './index.js';
test('quacks like an array', t => {
const fixture = negativeArray(['foo', 'bar', 'baz']);
t.is(fixture.length, 3);
t.is(fixture.toString(), 'foo,bar,baz');
});
test('get values', t => {
const fixture = negativeArray(['foo', 'bar', 'baz']);
t.is(fixture[0], 'foo');
t.is(fixture[1], 'bar');
t.is(fixture[-1], 'baz');
t.is(fixture[-2], 'bar');
});
test('set values', t => {
const fixture = negativeArray(['foo', 'bar', 'baz']);
fixture[0] = 0;
t.deepEqual(fixture, [0, 'bar', 'baz']);
fixture[1] = 1;
t.deepEqual(fixture, [0, 1, 'baz']);
fixture[-1] = -1;
t.deepEqual(fixture, [0, 1, -1]);
fixture[-2] = -2;
t.deepEqual(fixture, [0, -2, -1]);
});
test('only accepts arrays', t => {
t.throws(() => {
negativeArray({});
});
});