Unable to have a real time key event in text area for unit cases in react

keyDown simulation should only take keyCode value. Try it like this:

component.find('.text-area').simulate('keyDown', { keyCode: 'k'});

And the jsx should be like this:

<textarea
    className='text-area'
    onChange={(e) => {
        this.setState({ textArea: e.target.value });
    }}
    onKeyDown={(e) => {
        this.setState({ textArea: e.keyCode });
    }}
>
    {this.state.textArea}
</textarea>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top