blog.sapegin.me icon indicating copy to clipboard operation
blog.sapegin.me copied to clipboard

Simulate in Modern React testing, part 2: Jest and Enzyme

Open vkrol opened this issue 5 years ago • 3 comments

The name simulate() is misleading: it doesn’t really simulate an event but calls the prop the same way we’d do it manually. These two lines will do almost the same:

As far as I know, it's only true for shallow rendering. mount uses ReactTestUtils.Simulate (https://reactjs.org/docs/test-utils.html#simulate). I think it is worthwhile to clarify this.

vkrol avatar Aug 12 '19 21:08 vkrol

According to my experience it's not, but feel free to send any docs or code that proves otherwise.

sapegin avatar Aug 13 '19 07:08 sapegin

mount returns ReactWrapper. Here is the source code of ReactWrapper simulate: https://github.com/airbnb/enzyme/blob/master/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js#L345

shallow returns ShallowWrapper. Here is the source code of ShallowWrapper simulate: https://github.com/airbnb/enzyme/blob/master/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js#L448

vkrol avatar Aug 13 '19 07:08 vkrol

I don't want to bother you, but I can do the PR with a correction.

vkrol avatar Aug 27 '19 20:08 vkrol