-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed
Labels
Description
Since Redux Thunk 2.1.0, we can do something like this:
import * as api from '../api'
export default function configureStore(mocks) {
return createStore(
reducer,
applyMiddleware(thunk.withExtraArgument({
api,
// can also pass other modules you need in ACs and want to mock in tests
}))
);
}
Your action creators now don’t depend on those modules:
export function getUser(id) {
return (dispatch, getState, { api }) =>
api.getUser(id).then(() => dispatch({ ... }))
}
}
In tests, you should be able to call them directly with spies and pass your mocks as the third argument.
Looks perfectly testable to me. Seems like there is need for a third-party library.
What am I missing?
phusick and jbinto