@@ -1098,7 +1098,7 @@ describe('createListenerMiddleware', () => {
10981098 expect ( takeResult ) . toBe ( null )
10991099 } )
11001100
1101- test ( "take resolves to [A, CurrentState, PreviousState] if the timeout is provided but doesn't expires " , async ( ) => {
1101+ test ( "take resolves to [A, CurrentState, PreviousState] if the timeout is provided but doesn't expire " , async ( ) => {
11021102 const store = configureStore ( {
11031103 reducer : counterSlice . reducer ,
11041104 middleware : ( gDM ) => gDM ( ) . prepend ( middleware ) ,
@@ -1122,6 +1122,43 @@ describe('createListenerMiddleware', () => {
11221122 expect ( takeResult ) . toEqual ( [ increment ( ) , stateCurrent , stateBefore ] )
11231123 } )
11241124
1125+ test ( "take resolves to `[A, CurrentState, PreviousState] | null` if a possibly undefined timeout parameter is provided" , async ( ) => {
1126+ const store = configureStore ( {
1127+ reducer : counterSlice . reducer ,
1128+ middleware : ( gDM ) => gDM ( ) . prepend ( middleware ) ,
1129+ } )
1130+
1131+ type ExpectedTakeResultType = readonly [ ReturnType < typeof increment > , CounterState , CounterState ] | null
1132+
1133+ let timeout : number | undefined = undefined
1134+ let done = false
1135+
1136+ const startAppListening = startListening as TypedStartListening < CounterState >
1137+ startAppListening ( {
1138+ predicate : incrementByAmount . match ,
1139+ effect : async ( _ , listenerApi ) => {
1140+ const stateBefore = listenerApi . getState ( )
1141+
1142+ let takeResult = await listenerApi . take ( increment . match , timeout )
1143+ const stateCurrent = listenerApi . getState ( )
1144+ expect ( takeResult ) . toEqual ( [ increment ( ) , stateCurrent , stateBefore ] )
1145+
1146+ timeout = 1
1147+ takeResult = await listenerApi . take ( increment . match , timeout )
1148+ expect ( takeResult ) . toBeNull ( )
1149+
1150+ expectType < ExpectedTakeResultType > ( takeResult )
1151+
1152+ done = true
1153+ } ,
1154+ } )
1155+ store . dispatch ( incrementByAmount ( 1 ) )
1156+ store . dispatch ( increment ( ) )
1157+
1158+ await delay ( 25 )
1159+ expect ( done ) . toBe ( true ) ;
1160+ } )
1161+
11251162 test ( 'condition method resolves promise when the predicate succeeds' , async ( ) => {
11261163 const store = configureStore ( {
11271164 reducer : counterSlice . reducer ,
0 commit comments