Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit tests - flux and data persistency

I'm encountering a fun little problem with unit testing and the flux data stores.

Since the data stores are singletons that only get instantiated once (when the module is imported) any changes you make in your unit test persist.

This can (and is) causing me all sorts of head aches.

The solution I'm currently implementing is a reset method on each store which I run within the afterEach but I was wondering / hoping there's a simpler way to go around this?

like image 628
Guy Nesher Avatar asked Oct 22 '14 15:10

Guy Nesher


1 Answers

Require your dispatcher, store and get the reference to the callback all within a beforeEach(). This blows away the old stuff and gives you fresh stuff for each test.

Example of this is in the blog post: http://facebook.github.io/react/blog/2014/09/24/testing-flux-applications.html#putting-it-all-together

like image 187
fisherwebdev Avatar answered Oct 21 '22 19:10

fisherwebdev