Search code examples
jasminereactjsreactjs-flux

flux store - unit tests


I'm writing unit tests for several Flux stores and encountered a small annoyance.

My stores are generally built like this:

storeObj = {
...
}

_secretsetterfunction = function (){}

module.exports storeObj

As you can see, since the setter function is outside of the store object - it's not directly accessible.

This presents a problem as the only way to test / manipulate the store data would be to go through the Action -> Dispatcher -> event listener (the Action can technically be cut out) which isn't something I would like to go through when unit testing a store.

The alternative is to actually put the setter methods on the store object - but this isn't something I'd really wish to do.

Any thoughts?


Solution

  • So The flux team just addressed this in a blog post, though they are using their own variant called Jest. Still worth a read:

    http://facebook.github.io/react/blog/2014/09/24/testing-flux-applications.html?utm_source=javascriptweekly&utm_medium=email