-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
57 lines (48 loc) · 1.56 KB
/
tests.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
import fs from 'fs';
import path from 'path';
import util from 'util';
import test from 'ava';
import rbjs from '.';
const readdir = util.promisify(fs.readdir);
test('proxy array objects', t => {
const proxied = rbjs([]);
t.true(proxied.__rbjs__);
});
test('do not proxy and return non-array objects', t => {
const proxied = rbjs('string');
t.is(proxied.__rbjs__, undefined);
});
test('proxied array contains all defined methods', async t => {
const methods = await readdir(path.join(__dirname, 'methods'));
const proxied = rbjs([]);
methods.forEach(method => {
t.true(method in proxied);
t.is(typeof proxied[method], 'function');
});
});
test('built-in methods return proxied instances', t => {
const proxied = rbjs([1, 2, 3, [5, 6, 7]]);
const doubled = proxied[3].map(x => x * 2);
t.true(doubled.__rbjs__);
/*
* Concordance rules can differentiate between a normal array
* and a wrapped (proxied) array. See:
* https://github.com/concordancejs/concordance#comparison-details
* So we spread the proxied array back to a normal array.
*/
t.deepEqual([...doubled], [10, 12, 14]);
});
test('custom methods are chainable', t => {
const proxied = rbjs([
[1, 2, 3],
[4, 5, 6]
], 4);
const result = proxied.assoc(4);
t.deepEqual([...result], [4, 5, 6]);
t.true('any' in result);
t.notThrows(() => result.any(Boolean));
});
test('non-function properties return the correct values', t => {
const proxied = rbjs([1, 2, 3, 4, 5]);
t.is(proxied.length, 5);
});