@@ -3,38 +3,78 @@ import expect, { createSpy } from 'expect'
3
3
import { recursive } from 'src/index'
4
4
5
5
describe ( 'recursive' , ( ) => {
6
+ let id
7
+ let constant
8
+
9
+ beforeEach ( ( ) => {
10
+ id = createSpy ( ) . andCall ( value => value )
11
+ constant = createSpy ( ) . andCall ( value => _ => value )
12
+ } )
13
+
6
14
it ( 'should be a function' , ( ) => {
7
15
expect ( recursive ) . toBeA ( Function )
8
16
} )
9
17
10
- describe ( 'recursive(identity)("one", "two")' , ( ) => {
11
- let internal
12
- let identity
18
+ describe ( 'recursive(id)("one", "two")' , ( ) => {
19
+ let rec
13
20
14
21
beforeEach ( ( ) => {
15
- internal = createSpy ( ) . andCall ( value => value )
16
- identity = recursive ( self => internal )
22
+ rec = recursive ( self => id )
17
23
} )
18
24
19
- const subject = ( ) => identity ( 'one' , 'two' )
25
+ const subject = ( ) => rec ( 'one' , 'two' )
20
26
21
27
it ( 'should be called with ("one", "two")' , ( ) => {
22
28
subject ( )
23
29
24
- expect ( internal ) . toHaveBeenCalledWith ( 'one' , 'two' )
30
+ expect ( id ) . toHaveBeenCalledWith ( 'one' , 'two' )
25
31
} )
26
32
27
33
it ( 'should be called 1 time' , ( ) => {
28
34
subject ( )
29
35
30
- expect ( internal . calls . length ) . toEqual ( 1 )
36
+ expect ( id . calls . length ) . toEqual ( 1 )
31
37
} )
32
38
33
39
it ( 'should return "one"' , ( ) => {
34
40
expect ( subject ( ) ) . toEqual ( 'one' )
35
41
} )
36
42
} )
37
43
44
+ describe ( 'recursive(id, [() => const("three")])("one", "two")' , ( ) => {
45
+ let subject
46
+ let middleware
47
+
48
+ beforeEach ( ( ) => {
49
+ middleware = createSpy ( ) . andCall ( ( ) => constant ( 'three' ) )
50
+ subject = recursive ( self => id , [
51
+ middleware ,
52
+ ] )
53
+ } )
54
+
55
+ it ( 'should not call λ(id)' , ( ) => {
56
+ subject ( )
57
+
58
+ expect ( id ) . toNotHaveBeenCalled ( )
59
+ } )
60
+
61
+ it ( 'should call λ(middleware) with λ(id)' , ( ) => {
62
+ subject ( )
63
+
64
+ expect ( middleware ) . toHaveBeenCalled ( id )
65
+ } )
66
+
67
+ it ( 'should call λ(const) with λ(three)' , ( ) => {
68
+ subject ( )
69
+
70
+ expect ( constant ) . toHaveBeenCalled ( 'three' )
71
+ } )
72
+
73
+ it ( 'should return "three"' , ( ) => {
74
+ expect ( subject ( 'one' , 'two' ) ) . toEqual ( 'three' )
75
+ } )
76
+ } )
77
+
38
78
describe ( 'recursive(sum)([1, 2, 3])' , ( ) => {
39
79
let internal
40
80
let sum
0 commit comments