We used react for about one year now, with immutable data, very impressive. We now want to move to Clojurescript/Reagent, but we need a very good way to test our code. For components this is what we did:
- Test the output of the component, depending on the props we sent:
- Test that the component invokes the right functions and with the right parameters when an event like click occurs
For 1 it would be like:
function renderFFC(filters, search_criterias)
{
return TestUtils.renderIntoDocument(React.createElement(FilterIntervalNumberComponent,{filter:filters, search_criteria:search_criterias}));
}
describe("IN", function(){
it("should render search criteria - interval", function() {
var criterias = {};
var ffc = renderFFC(filter, criterias);
expect(ffc.refs[0].getDOMNode().value).toBeNull();
expect(ffc.refs[1].getDOMNode().value).toBeNull();
});
For 2 it would be something like:
describe("OUT", function(){
it("should change the values, then click - boolean ", function() {
//mock function
set_criteria_and_search = jest.genMockFunction();
var fbc = renderFBC(filter, {});
React.addons.TestUtils.Simulate.change(fbc.refs.yes.getDOMNode(),{nativeEvent: {target: {value: true}}});
expect(controller.set_criteria_and_search.mock.calls)
.toEqual(
[['taxes_applied',{'taxes_applied':[{value:"1"}]}]]
);
});
We used facebook Jest for the tests.
How do I dothe same thing in Clojurescript with Reagent, preferably having the tests automatically run?