File size: 812 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { mergeHandlers } from '../utils';

describe( '#mergeHandlers', () => {
	const inc = ( a ) => a + 1;
	const triple = ( a ) => a * 3;
	const action = 'DO_MATH';
	const first = { [ action ]: [ inc ] };
	const second = { [ action ]: [ triple ] };

	test( 'should pass through a single handler', () => {
		expect( mergeHandlers( first ) ).toEqual( first );
	} );

	test( 'should combine lists of handlers for different action types', () => {
		const merged = mergeHandlers( { INCREMENT: [ inc ] }, { TRIPLE: [ triple ] } );

		expect( merged ).toEqual( {
			INCREMENT: [ inc ],
			TRIPLE: [ triple ],
		} );
	} );

	test( 'should combine lists of handlers for the same action type', () => {
		const merged = mergeHandlers( first, second );

		expect( merged[ action ] ).toEqual( [ inc, triple ] );
	} );
} );