Last time we started creating our Reducks library by implementing the
createStore and while I have all confidence in my ability to write bug free code we do have some tests in the demo app, so let’s use them.
So, where do we start?
It’s actually not that complex in the way you would do this, normally within the code base you would have:
The next step is change what we export to instead of just being the function to run you wrap it in. So with our
index.redux.js file I have renamed that to
index.js and added a new export:
Now we can create a new
index.redux.js file that looks like so:
And we can also create
Then you can run it:
PS> npm run reducks-demo
I’m using mocha as my test framework so normally you’d write a test like so:
Well I’d be remiss to not ensure that the tests work with both libraries, so to do that I’m going to wrap the
it scenario so that I can inject the the
createStore function (and I also pushed it into a separate file):
Now let’s change how our test is setup:
Object.keys I can go through the hash that’s exported and create the
it call, passing in the
createStore. For readability I’ve also wrapped the test scenarios in a nested
describe so that I can identify which library the tests were run against.
This was a simple little post where we looked at how we refactored the existing code to support being able to use different implementations of Redux and support our test scenarios as we work on more features.
I’ve updated the repository with a new tag that shows the progress.