-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
79 lines (64 loc) · 1.38 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
import test from 'ava'
import inject from './'
test.beforeEach(t => {
const double = x => x * 2
const triple = x => x * 3
t.context.func = inject(({double, triple}) => (
x => double(x) + triple(x)
))({double, triple})
})
test('Works with default dependencies', t => {
const {func} = t.context
t.is(func(1), 5)
})
test('Allows injection', t => {
const {func} = t.context
const func2 = func.inject({
double: x => x,
triple: x => x
})
t.is(func2(1), 2)
})
test('Allows partial injection', t => {
const {func} = t.context
const func2 = func.inject({
double: x => x
})
t.is(func2(1), 4)
})
test('Works with no overrides passed', t => {
const {func} = t.context
const func2 = func.inject()
t.is(func2(1), 5)
})
test('keeps independent instances', t => {
const {func} = t.context
const func2 = func.inject({
double: x => x,
triple: x => x
})
const func3 = func.inject({
double: x => x * 3,
triple: x => x * 4
})
t.is(func(1), 5)
t.is(func2(1), 2)
t.is(func3(1), 7)
t.is(func(1), 5)
})
test('produces identical instances', t => {
const {func} = t.context
const func2 = func.inject({
double: x => x,
triple: x => x
})
// note func2.inject
const func3 = func2.inject({
double: x => x * 3,
triple: x => x * 4
})
t.is(func(1), 5)
t.is(func2(1), 2)
t.is(func3(1), 7)
t.is(func(1), 5)
})