File size: 1,142 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
30
import { queryToPredicate } from '..';

describe( 'consoleDispatcher', () => {
	describe( 'queryToPredicate', () => {
		test( 'should transform RegExp to arg.type predicate function', () => {
			const predicate = queryToPredicate( /^MATCH_ME$/ );
			expect( predicate( { type: 'MATCH_ME' } ) ).toBe( true );
			expect( predicate( { type: 'DONT_MATCH_ME' } ) ).toBe( false );
		} );

		test( 'should transform string to arg.type predicate function', () => {
			const predicate = queryToPredicate( 'MATCH_ME' );
			expect( predicate( { type: 'MATCH_ME' } ) ).toBe( true );
			expect( predicate( { type: 'DONT_MATCH_ME' } ) ).toBe( false );
		} );

		test( 'should return a provided function untouched', () => {
			const predicateReturn = {};
			const predicate = queryToPredicate( () => predicateReturn );
			expect( predicate() ).toBe( predicateReturn );
		} );

		test( 'should throw an Error if unrecognized query is provided', () => {
			expect( () => queryToPredicate() ).toThrow( TypeError );
			expect( () => queryToPredicate( 1 ) ).toThrow( TypeError );
			expect( () => queryToPredicate( {} ) ).toThrow( TypeError );
		} );
	} );
} );