redux-mock-store
redux-mock-store copied to clipboard
Provide action to subscribed functions.
It's useful among subscribers to know which action is being dispatched. This PR provides the action object to subscribed functions.
Thanks for the review, @ohtangza.
I would love to get this merged so I can stop using my forked version of this repo. 😆
@AndrewSouthpaw My pleasure, let's wait for @arnaudbenard response then.
I'd love to see this happen.
Actually I was hoping it would follow the reducer API:
store.subscribe((state, action) => console.log('!!DISPATCH!!!', state, action));
But I guess the mock state never changes, so just having action is fine, too..
I don't think it follows the redux design, check this https://github.com/reactjs/redux/blob/master/docs/faq/DesignDecisions.md#does-not-pass-state-action-to-subscribers
@dmitry-zaets what do you think?
That's true... it does break from the design.
I thought it wouldn't be critical to follow that same design choice, since this is a mock store intended for testing purposes. The state never changes anyway, so the concept of batching isn't particularly relevant, while it can be useful in tests to subscribe to particular actions firing in the store.
Ping. :)
If not this solution, is there an alternative way that you could still get the state passed in. that would be helpful in testing components that are wrapped in connect()
call because it would allow you to test your mapStateToProps
function without having to export it publicly. instead you simply dispatch an action and assert on the props of the connected component
@abe4mvp If I understand you correctly, that would require a working reducer to be hooked into the store, which is currently not possible. I've actually extended this repo to allow that, so I find it helpful, but... yeah. Not sure if that's beyond what would be considered "proper" for this repo.
Ping?
I implemented this in my TypeScript fork @jedmao/redux-mock-store
if you want to take a look!