license import { Action , Reducer , combineReducers } from "../index" ; function constant ( payload ) { return { type : "test::constant" , payload , } ; } const add = ( state , action ) => { if ( action . type === "test::constant" ) { return state + action . payload ; } return state ; } ; describe ( "combineReducers" , ( ) => { it ( "should not throw on empty map input" , ( ) => { const reducer = combineReducers ( { } ) ; expect ( reducer ( { } , constant ( 0 ) ) ) . toEqual ( { } ) ; } ) ; it ( "should delegate to a single reducer for a key" , ( ) => { const reducer = combineReducers ( { a : add } ) ; expect ( reducer ( { a : 4 } , constant ( 5 ) ) ) . toEqual ( { a : 9 } ) ; } ) ; it ( "should delegate to multiple reducers for each action" , ( ) => { const reducer = combineReducers ( { a : add , b : add } ) ; expect ( reducer ( { a : 4 , b : 40 } , constant ( 5 ) ) ) . toEqual ( { a : 9 , b : 45 } ) ; } ) ; it ( "should throw on first invocation if state and reducers have mismatched shape" , ( ) => { const reduceA = combineReducers < any > ( { a : add } ) ; expect ( ( ) => reduceA ( { a : 4 , b : 40 } , constant ( 5 ) ) ) . toThrow ( ) ; const reduceAB = combineReducers < any > ( { a : add , b : add } ) ; expect ( ( ) => reduceAB ( { a : 4 } , constant ( 5 ) ) ) . toThrow ( ) ; } ) ; describe ( "initial state handling" , ( ) => { it ( "should not throw on creation (initial state handled externally)" , ( ) => { const reducer = combineReducers ( { a : add } ) ; expect ( reducer ) . toBeDefined ( ) ; } ) ; it ( "should throw when a reducer returns undefined on input state == null" , ( ) => { const reducer = combineReducers ( { a : add , b : ( ) => 0 } ) ; expect ( ( ) => reducer ( undefined as any , { type : "redoodle/test/INIT" , payload : { } } ) ) . toThrow ( ) ; } ) ; } ) ; } ) ;