recently started using recompose (https://github.com/acdlite/recompose)
I wonder how should I approach unit testing components that are wrapped with some of hocs recompose provide? I love how entire class component can be replaced with functional approach but it totally not true in terms of unit tests.
For example with given list component
export const ListItem = toClass(pure(({ text }) => <li>{text}</li>));
const renderItems = R.map(t => <ListItem key={t} text={t} />);
export const ListComponent = toClass(({ todos, name, updateName, addTodo }) =>
<div>
<input onChange={updateName} value={name} />
<button onClick={() => addTodo(name)}>add todo</button>
<ul>
{renderItems(todos)}
</ul>
</div>
);
...
const List = compose(
withReducer("state", "dispatch", listReducer, props => ({
...initialState,
...props
})),
withHandlers({
updateName: ({ dispatch }) => e =>
dispatch({ type: "UPDATE_NAME", payload: e.target.value }),
addTodo: ({ dispatch, name }) => name =>
dispatch({ type: "ADD_TODO", payload: name })
}),
flattenProp("state")
)(ListComponent);
export default List;
How can I test children length with given props? I've tried something like this but it's not working.
it("renders todos list", () => {
const component = shallow(<List todos={["todo1", "todo2", "todo3"]} />);
expect(component.instance().children).toHaveLength(3);
});