-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransmute.js
60 lines (48 loc) · 1.9 KB
/
transmute.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
import describe from 'tape-bdd';
import transmute from 'transmutation';
const promise = new Promise(res => res({ test: 'promise' }));
describe('Transmute', (it) => {
it('does not change a null value', assert => transmute(null)
.then(value => assert.deepEqual(value, null))
);
it('does not change an integer', assert => transmute(5)
.then(value => assert.deepEqual(value, 5))
);
it('does not change a string', assert => transmute('roar')
.then(value => assert.deepEqual(value, 'roar'))
);
it('does not change an object', assert => transmute({ test: 'roar' })
.then(value => assert.deepEqual(value, { test: 'roar' }))
);
it('does not change an array', assert => transmute([0, 'ten'])
.then(value => assert.deepEqual(value, [0, 'ten']))
);
it('handles the result of a promise', assert => transmute(promise)
.then(value => assert.deepEqual(value, { test: 'promise' }))
);
it('recursively handles transmuted values', assert => transmute(transmute(promise))
.then(value => assert.deepEqual(value, { test: 'promise' }))
);
it('prepares a pipeline for data', (assert) => {
const pipeline = transmute()
.extend({ roar: 'hello' });
return pipeline({ test: 'stuff' })
.then(value => assert.deepEqual(value, {
test: 'stuff',
roar: 'hello',
}));
});
it('prepares a pipeline that can be extended later', (assert) => {
const pipeline = transmute();
const newPipeline = pipeline
.extend({ roar: 'hello' });
const newerPipeline = newPipeline
.extend({ stuff: 'another' });
return newerPipeline({ test: 'stuff' })
.then(value => assert.deepEqual(value, {
test: 'stuff',
roar: 'hello',
stuff: 'another',
}));
});
});