This is my component. It's basically a wrapper for another component. My question is how should I unit test this component? Apart from checking state and calling the two methods and making sure they update the state.
Apart from that, that just seems to render the props/state so is there any need to test this?
import React from 'react';
import { PropTypes as PT } from 'prop-types';
export default Wrapped =>
class extends React.Component {
static propTypes = {
numOne: PT.number,
};
constructor(props) {
super(props);
this.state = {
showModal: false,
};
}
openModal = () => {
this.setState({
showModal: true,
});
};
closeModal = () => {
this.setState({
showModal: false,
});
};
render() {
return (
<Wrapped
numberValue={this.props.numOne}
showHolidayModal={this.state.showHolidayListModal}
showModal={this.openModal}
closeModal={this.closeModal}
{...this.props}
/>
);
}
};
This is my component (just example) Which I am also unit testing, that it renders what is passed in
import React from 'react';
import { PropTypes as PT } from 'prop-types';
import container from './container';
import { Card, Button, Modal } from '../common';
export const Leave = props => {
return (
<div>
<span>Dummy data : {props.numberValue}</span>
{props.showModal && <Modal />}
<Button onClick={props.closeModal} label="close" />
</div>
);
};
Leave.propTypes = {
numberValue: PT.number,
showModal: PT.bool,
openModal: PT.func,
closeModal: PT.func,
};
export default container(Leave);
Wrappedcomponent renders aWrappedinside it? Is it an infinite recursion? - Murilo Cruz