Having the following comp
constructor(props) {
super(props);
this.state = {
comment: ''
}
}
handleChange = event => {
this.setState({ [event.target.name]: event.target.value })
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<h4>Add a Comment</h4>
<textarea name="comment" onChange={this.handleChange} value={this.state.comment} />
<div>
<button>Submit Comment</button>
</div>
</form>
)
}
wont let me pass the test when writting the following
it('has a text area where the users can type in', () => {
wrapped.find('textarea').simulate('change', {
target: {value: 'new comment'}
})
wrapped.update()
expect(wrapped.find('textarea').prop('value')).toEqual('new comment')
})
But the same test passes when using the following handlechange
handleChange = event => {
this.setState({ comment: event.target.value })
}
How can I make this test pass while using [event.target.name]