1
- import { compose } from '../ '
1
+ import { compose } from '..'
2
2
3
3
describe ( 'Utils' , ( ) => {
4
4
describe ( 'compose' , ( ) => {
5
5
it ( 'composes from right to left' , ( ) => {
6
- const double = x => x * 2
7
- const square = x => x * x
6
+ const double = ( x : number ) => x * 2
7
+ const square = ( x : number ) => x * x
8
8
expect ( compose ( square ) ( 5 ) ) . toBe ( 25 )
9
9
expect (
10
10
compose (
@@ -22,10 +22,10 @@ describe('Utils', () => {
22
22
} )
23
23
24
24
it ( 'composes functions from right to left' , ( ) => {
25
- const a = next => x => next ( x + 'a' )
26
- const b = next => x => next ( x + 'b' )
27
- const c = next => x => next ( x + 'c' )
28
- const final = x => x
25
+ const a = ( next : ( x : string ) => string ) => ( x : string ) => next ( x + 'a' )
26
+ const b = ( next : ( x : string ) => string ) => ( x : string ) => next ( x + 'b' )
27
+ const c = ( next : ( x : string ) => string ) => ( x : string ) => next ( x + 'c' )
28
+ const final = ( x : string ) => x
29
29
30
30
expect (
31
31
compose (
@@ -51,14 +51,15 @@ describe('Utils', () => {
51
51
} )
52
52
53
53
it ( 'throws at runtime if argument is not a function' , ( ) => {
54
- const square = x => x * x
55
- const add = ( x , y ) => x + y
54
+ type sFunc = ( x : number , y : number ) => number
55
+ const square = ( x : number , _ : number ) => x * x
56
+ const add = ( x : number , y : number ) => x + y
56
57
57
58
expect ( ( ) =>
58
59
compose (
59
60
square ,
60
61
add ,
61
- false
62
+ ( false as unknown ) as sFunc
62
63
) ( 1 , 2 )
63
64
) . toThrow ( )
64
65
expect ( ( ) =>
@@ -72,28 +73,28 @@ describe('Utils', () => {
72
73
compose (
73
74
square ,
74
75
add ,
75
- true
76
+ ( true as unknown ) as sFunc
76
77
) ( 1 , 2 )
77
78
) . toThrow ( )
78
79
expect ( ( ) =>
79
80
compose (
80
81
square ,
81
82
add ,
82
- NaN
83
+ ( NaN as unknown ) as sFunc
83
84
) ( 1 , 2 )
84
85
) . toThrow ( )
85
86
expect ( ( ) =>
86
87
compose (
87
88
square ,
88
89
add ,
89
- '42'
90
+ ( '42' as unknown ) as sFunc
90
91
) ( 1 , 2 )
91
92
) . toThrow ( )
92
93
} )
93
94
94
95
it ( 'can be seeded with multiple arguments' , ( ) => {
95
- const square = x => x * x
96
- const add = ( x , y ) => x + y
96
+ const square = ( x : number , _ : number ) => x * x
97
+ const add = ( x : number , y : number ) => x + y
97
98
expect (
98
99
compose (
99
100
square ,
@@ -103,9 +104,9 @@ describe('Utils', () => {
103
104
} )
104
105
105
106
it ( 'returns the first given argument if given no functions' , ( ) => {
106
- expect ( compose ( ) ( 1 , 2 ) ) . toBe ( 1 )
107
+ expect ( compose < number > ( ) ( 1 , 2 ) ) . toBe ( 1 )
107
108
expect ( compose ( ) ( 3 ) ) . toBe ( 3 )
108
- expect ( compose ( ) ( ) ) . toBe ( undefined )
109
+ expect ( compose ( ) ( undefined ) ) . toBe ( undefined )
109
110
} )
110
111
111
112
it ( 'returns the first function if given only one' , ( ) => {
0 commit comments