I am new to enzyme testing and I created the component as:
import React from 'react';
import {
compose,
withState,
withHandlers,
branch,
pure,
renderComponent,
} from 'recompose';
import Fields from './components/Fields';
import Flow from './components/Flow';
export const MODE = {
preview: 'preview',
edit: 'edit',
};
const inEditMode = ({ mode }) => mode === MODE.edit;
const Component = branch(
inEditMode,
renderComponent(Fields),
renderComponent(Flow),
)(Flow);
const Tab = pure(props => <Component {...props} />);
export default compose(
withState('mode', 'changeMode', props => {
const path = props.path;
return props.path ? MODE.preview : MODE.edit;
}),
withHandlers({
changeMode: ({ changeMode }) => () => changeMode(currentState => currentState === MODE.preview ? MODE.edit : MODE.preview),
onApprovalChange: ({ onAction, entity }) => data => {
onAction({ ...data, status: 'UPDATED' }, data.id);
},
}),
)(Tab);
In the above component, I want to check the following:
Drawing Component
inEditMode component function
Handlers present in withStateandwithHandlers
branch recompose utility (I really don't think I need to test this because they already could, but suppose I want to test such a function)
I could find stackoverflow documentation on testing, but there was not a single resource that could give a general idea.
source
share