blog.sapegin.me
blog.sapegin.me copied to clipboard
Simulate in Modern React testing, part 2: Jest and Enzyme
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.
According to my experience it's not, but feel free to send any docs or code that proves otherwise.
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
I don't want to bother you, but I can do the PR with a correction.