Hello I to create a test for a cancel button in a material ui based dialog window with Mocha and Enzyme and Chai but I get an error can read property of undefined.
My dialog window:
class DialogWindow extends Component {
constructor() {
super();
this.state = {
open: false
};
}
handleRequestClose() {
this.setState({open: false});
}
render() {
return (
<Dialog
onClose={this.handleRequestClose}
open={this.state.open}
render={({
Icon,
getIconProps,
getTitleProps,
getContentProps,
getActionsProps
}) => (
<div>
<Icon {...getIconProps()} />
<DialogTitle {...getTitleProps()}>
entry
</DialogTitle>
<DialogContent {...getContentProps()}>
Are you sure you want to proceed?
</DialogContent>
<DialogActions {...getActionsProps()}>
<Button onClick={this.handleRequestClose.bind(this)}>Cancel</Button>
</DialogActions>
</div>
)}
{...this.props}
/>
);
}
}
export default connect()(DialogWindow);
And my test for the cancel button I am not sure if I can access a child of child like this:
describe('Cancel button test', () => {
it('cancel button on the dialog window works', () => {
const wrapper = shallow(
<Provider store = {store}>
<DialogWindow.WrappedComponent />
</Provider>).dive();
wrapper.setState({ open: true });
const dialog = wrapper.find('Dialog').at(0);
const cancelButton = dialog.find('button').at(0);
cancelButton.simulate('click');
expect(wrapper.state().open).to.eql(false);
});
});
Aucun commentaire:
Enregistrer un commentaire