-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathpipe.ts
37 lines (30 loc) · 1.18 KB
/
pipe.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
/**
* Internal dependencies
*/
import pipe from '../pipe';
describe( 'pipe', () => {
it( 'returns the initial value if no functions are specified', () => {
expect( pipe()( 'test' ) ).toBe( 'test' );
} );
it( 'executes functions left-to-right when passed as separate arguments', () => {
const a = ( value ) => ( value += 'a' );
const b = ( value ) => ( value += 'b' );
const c = ( value ) => ( value += 'c' );
expect( pipe( a, b, c )( 'test' ) ).toBe( 'testabc' );
} );
it( 'executes functions left-to-right when passed as a single array', () => {
const a = ( value ) => ( value += 'a' );
const b = ( value ) => ( value += 'b' );
const c = ( value ) => ( value += 'c' );
expect( pipe( [ a, b, c ] )( 'test' ) ).toBe( 'testabc' );
} );
it( 'executes functions left-to-right 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( pipe( [ a, b ], c, [ d ], e )( 'test' ) ).toBe( 'testabcde' );
} );
} );