redux-mock-store icon indicating copy to clipboard operation
redux-mock-store copied to clipboard

Provide action to subscribed functions.

Open AndrewSouthpaw opened this issue 7 years ago • 10 comments

It's useful among subscribers to know which action is being dispatched. This PR provides the action object to subscribed functions.

AndrewSouthpaw avatar Nov 09 '17 22:11 AndrewSouthpaw

Thanks for the review, @ohtangza.

I would love to get this merged so I can stop using my forked version of this repo. 😆

AndrewSouthpaw avatar Dec 29 '17 00:12 AndrewSouthpaw

@AndrewSouthpaw My pleasure, let's wait for @arnaudbenard response then.

ohtangza avatar Dec 29 '17 01:12 ohtangza

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..

crazy4groovy avatar Jan 19 '18 17:01 crazy4groovy

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?

arnaudbenard avatar Jan 22 '18 20:01 arnaudbenard

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.

AndrewSouthpaw avatar Jan 23 '18 00:01 AndrewSouthpaw

Ping. :)

AndrewSouthpaw avatar May 09 '18 18:05 AndrewSouthpaw

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 avatar May 22 '18 15:05 abe4mvp

@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.

AndrewSouthpaw avatar May 23 '18 18:05 AndrewSouthpaw

Ping?

AndrewSouthpaw avatar Aug 22 '18 13:08 AndrewSouthpaw

I implemented this in my TypeScript fork @jedmao/redux-mock-store if you want to take a look!

jednano avatar Jul 12 '19 19:07 jednano