react-fluxible-utils
A collection of extremely useful utils and components for React+Fluxible applications.
To start using this library, first install the package:
npm install react-fluxible-utils --save
Then you're all set up to use the following utils and components:
reactSafeRender
A wrapper around React, to handle errors thrown by the render method and life-cycle events. To use this wrapper, just replace the line where you import React with:
// ES6 syntax; // ES5 syntaxconst React = ReactSafeRender;
connectToStores
A wrapper around the Fluxible connectToStores
. The purpose of this wrapper is to not lose the original component as normally is the case, but still have it accessible as a .original
property. This is needed when testing a component with the shallowComponent
utility as described later. To use this wrapper, just replace the line where you import connectToStores
with:
// ES6 syntax; // ES5 syntaxconst connectToStores = connectToStores;
shallowComponent
A class useful for testing React components. This can be used as follows:
;;; // in your tests, you can now do things like this:const component = ComponentToTest; // then you can use component for easily writing tests:; // assuming your using chaitobeok;tohavedeepthatdeep;tohavelength5; // you can even test store connections; // assuming your using sinonconst sampleData = xxx: 'yyy';sinon;const componentWithStore = component;tohavedeepthatdeep;StoreprototypegetDetails;
mockDispatcher
A class useful for testing Fluxible stores. This can be used as follows:
;; // in your tests, you can now do things like this:const dispatcherMock = StoreToTest;const store = dispatcherMock; // then you can mock event dispatching for easily writing tests:; // assuming your using chaiconst sampleData = foo: 'bar';dispatcherMock;to;