How do you simulate an keyDown enter event (or others) in Enzyme?

后端 未结 8 798
臣服心动
臣服心动 2021-02-02 06:08

I\'m trying to simulate a keyDown event, specifically for Enter, keyCode: 13. I\'ve tried a number of different ways of doing this, but none of them ar

8条回答
  •  春和景丽
    2021-02-02 06:18

    Simulate solution is deprecated

    Enzyme simulate is supposed to be removed in version 4. Main maintainer is suggesting directly invoking prop functions. One solution is to directly test that invoking those props does the right thing; or you can mock out instance methods, test that the prop functions call them and unit test the instance methods.

    You could call key down for example

    wrapper.find('input').prop('onKeyDown')({ key: 'Enter' }) 
    

    or

    wrapper.find('input').props().onKeyDown({ key: 'Enter' }) 
    

    Information about deprecation: https://github.com/airbnb/enzyme/issues/2173

提交回复
热议问题