Repository: reduxjs/redux

Issue #546: testing async store.dispatch
Created: 2015-08-16T23:22:26Z
Maybe I'm overlooking something but I'm finding it impossible to test store.dispatch with an async action without a hacky timer solution.  In the below example actions.authenticate contains an ajax call.  The ajax call is mocked but its still in an async situation.  I'm using redux-thunk middlewear.  testTimeout() is just setTimeout with a 0 second delay.
Yes I know the design of redux allows the separate testing of actions, reducers, etc, but testing store.dispatch itself is a lot of bang for the buck because it ties store, reducers, actions and middlewear together.
      test( 'success', (done) => {                                                                                                                  

         fauxJaxResponse( '/authenticate', { 'the': 'token' } )                                                                                      

         store.dispatch( actions.authenticate( 'myname', 'mypass' ) )                                                                                

         testTimeout(()=>{                                                                                                                           
           // store.getState() asserts here                                                                                                                           
           done()                                                                                                                                    
         })                                                                                                                                          

       }) 

I could test actions and reducers together (below) bypassing store.dispatch but its incomplete because its bypassing any middlewear. Note that actions.authenticate() returns a thunk that calls mockDispatch when ready
test( 'success', (done) => {                                                                                                                  


  fauxJaxResponse( '/authenticate', { 'the': 'token' } )                                                                                            

   var mockDispatch = function( action ) {                                                                                                           
     state = reducer(action)                                                                                                                         
     // state asserts here                                                                                                                           
     done()                                                                                                                                          
   }                                                                                                                                                 

   actions.authenticate()( mockDispatch )  

})


I almost want store.dispatch() to take a callback as a second param, to be called when the dispatch is complete, but that's weird right, and only useful in testing?

Duplicate issue #700: How to write tests regarding Action Creators which return functions?
Created: 2015-09-10T06:59:21Z
It's mentioned in the documentation:
In Redux, action creators are functions which return plain objects. When testing action creators we want to test whether the correct action creator was called and also whether the right action was returned.

However, action creators can also return functions like this:
(dispatch, getState) => {...}
In this case, how do I write tests? It's not a simple checking object equality anymore.
Thank you

Closing comment (2015-09-13T17:44:40Z): Duplicate of #546.
See #546 (comment).

Maybe an idea to add this to the documentation?

I'd happily accept a pull request.