File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 1- export default function thunkMiddleware ( { dispatch , getState } ) {
2- return next => action => {
1+ function createThunkMiddleware ( extraArgument ) {
2+ return ( { dispatch , getState } ) => next => action => {
33 if ( typeof action === 'function' ) {
4- return action ( dispatch , getState ) ;
4+ return action ( dispatch , getState , extraArgument ) ;
55 }
66
77 return next ( action ) ;
88 } ;
99}
10+
11+ const thunk = createThunkMiddleware ( ) ;
12+ thunk . withExtraArgument = createThunkMiddleware ;
13+
14+ export default thunk ;
Original file line number Diff line number Diff line change @@ -76,4 +76,19 @@ describe('thunk middleware', () => {
7676 }
7777 } ) ;
7878 } ) ;
79+
80+ describe ( 'withExtraArgument' , ( ) => {
81+ it ( 'must pass the third argument' , done => {
82+ const extraArg = { lol : true } ;
83+ thunkMiddleware . withExtraArgument ( extraArg ) ( {
84+ dispatch : doDispatch ,
85+ getState : doGetState ,
86+ } ) ( ) ( ( dispatch , getState , arg ) => {
87+ chai . assert . strictEqual ( dispatch , doDispatch ) ;
88+ chai . assert . strictEqual ( getState , doGetState ) ;
89+ chai . assert . strictEqual ( arg , extraArg ) ;
90+ done ( ) ;
91+ } ) ;
92+ } ) ;
93+ } ) ;
7994} ) ;
You can’t perform that action at this time.
0 commit comments