-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathcompose.ts
39 lines (32 loc) · 1.21 KB
/
compose.ts
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
/**
* Internal dependencies
*/
import compose from '../compose';
describe( 'compose', () => {
it( 'returns the initial value if no functions are specified', () => {
expect( compose()( 'test' ) ).toBe( 'test' );
} );
it( 'executes functions right-to-left when passed as separate arguments', () => {
const a = ( value ) => ( value += 'a' );
const b = ( value ) => ( value += 'b' );
const c = ( value ) => ( value += 'c' );
expect( compose( a, b, c )( 'test' ) ).toBe( 'testcba' );
} );
it( 'executes functions right-to-left when passed as a single array', () => {
const a = ( value ) => ( value += 'a' );
const b = ( value ) => ( value += 'b' );
const c = ( value ) => ( value += 'c' );
expect( compose( [ a, b, c ] )( 'test' ) ).toBe( 'testcba' );
} );
it( 'executes functions right-to-left when passed as a mix of separate arguments and arrays', () => {
const a = ( value ) => ( value += 'a' );
const b = ( value ) => ( value += 'b' );
const c = ( value ) => ( value += 'c' );
const d = ( value ) => ( value += 'd' );
const e = ( value ) => ( value += 'e' );
const f = ( value ) => ( value += 'f' );
expect( compose( [ a, b ], c, [ d ], e )( 'test' ) ).toBe(
'testedcba'
);
} );
} );