quangbuule / redux-example

Another universal example.
375 stars 29 forks source link

How to test reducers #7

Open eguneys opened 9 years ago

eguneys commented 9 years ago

I have setup an redux application using this repo as an example. I have two reducers gamePlay and saveStore.

gamePlay store is a regular store using some state. saveStore store is a special store for saving properties on other stores and later restoring them.

In order for this to work, I make use of actions. Here's the gist of my application: https://gist.github.com/eguneys/a12bbe3b3e33254b3af2.

I have two questions:

  1. Is it a good idea to use stores/actions this way?
  2. How can I test the combined stores along with actions using middleware, that is whole redux application.

There are some examples here: https://github.com/gaearon/redux/pull/278/files#diff-755395ebcb422a6745dd7de738db93dbR1, but I couldn't figure out how to do it.

quangbuule commented 9 years ago

Here is my quick reply:

  1. That is ok, but you can use immutable.js to snapshot some of state of your application, this is better.
  2. Check out the redux 1.0.0RC (my example for that version: https://github.com/quangbuule/redux-example/tree/redux%40v1.0.0-rc)

The whole application now is just one store (each store in your mind now is one of store's properties) Then, if you want to test, just dispatch an action, and do assert on your only store.