I've been using Enzyme for a couple of years, and I've been happy with most of the time. But it happened to me a couple of times that I misread a snapshot, and a bug ended up in production!
Also, I've been teaching React to some colleagues lately, and I've realized it is not easy to understand Enzyme.
Add to this facts that I like to learn new stuff and use it in project always, and you'll understand why I switched recently to react-testing-library.
It is a different way of doing tests, tbh. People tend to understand it earlier because it is more similar to other unit tests techniques.
The only tradeoff (if you can call that) is that I have to mock way more stuff using react-testing-library than using Enzyme. It makes tests more verbose, but... I think I like it better! It helps me isolate what to test from a component.
So, that's my experience so far. Hope you find it useful.
From my experience, you'll have to rethink how to test stuff most of the time. A direct conversion from Enzyme to RTL won't work.
I always try to avoid testing implementation details. I don't have much details about your example, but in RTL is quite easy to get/set fields content, then you have to find the submit button, fire the click event, and expect some data to be sent.
I found way more difficult to test render props for instance...
And its hard to find material to study, I cant understand the Kodds examples too much :/
And I hate the fact that I cant find a comp by id or name hehe
The more u mock the less confidence u will have that all is well in the app/component.
I'd favor more integration type tests (that do less mocking , perhaps only mock out network/rest api cals) over 'unit' tests. As very unit versus integration is a thorny subject :)
I used to use Enzyme for a long time in my projects. However, now it is on deprecation path and will not be compatible with future versions of React. Therefore, I decided to write a tool that will help me and my team to migrate our projects to RTL. Check my article: dev.to/srshifu/migrate-away-from-e...
It has links to the tool you can download and use in your project
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I've been using Enzyme for a couple of years, and I've been happy with most of the time. But it happened to me a couple of times that I misread a snapshot, and a bug ended up in production!
Also, I've been teaching React to some colleagues lately, and I've realized it is not easy to understand Enzyme.
Add to this facts that I like to learn new stuff and use it in project always, and you'll understand why I switched recently to react-testing-library.
It is a different way of doing tests, tbh. People tend to understand it earlier because it is more similar to other unit tests techniques.
The only tradeoff (if you can call that) is that I have to mock way more stuff using react-testing-library than using Enzyme. It makes tests more verbose, but... I think I like it better! It helps me isolate what to test from a component.
So, that's my experience so far. Hope you find it useful.
I'm learning RTL and I use enzyme. I Try to reproduce the same tests that I use on enzyme to RTL, but I cant.
For example, how could I check if all form fields was filled and compare with a object that I'll send to backend?
From my experience, you'll have to rethink how to test stuff most of the time. A direct conversion from Enzyme to RTL won't work.
I always try to avoid testing implementation details. I don't have much details about your example, but in RTL is quite easy to get/set fields content, then you have to find the submit button, fire the click event, and expect some data to be sent.
I found way more difficult to test render props for instance...
hmmm I see.
And its hard to find material to study, I cant understand the Kodds examples too much :/
And I hate the fact that I cant find a comp by
idornameheheYou'll find the way, no worries...
I ended up using tons of data-testid in the mocks (I try really hard to avoid them in the real code).
I wanna try to avoid using it too, but how I use 3rd party components, I can't use
htmlForfor example, and I rarely use placeholderThe more u mock the less confidence u will have that all is well in the app/component.
I'd favor more integration type tests (that do less mocking , perhaps only mock out network/rest api cals) over 'unit' tests. As very unit versus integration is a thorny subject :)
have u any example ?
Favour Integration Tests - great article by the famous Kent C Dodds. His article says it better than me :)
I think that article moved here: Write tests. Not too many. Mostly integration.
I used to use Enzyme for a long time in my projects. However, now it is on deprecation path and will not be compatible with future versions of React. Therefore, I decided to write a tool that will help me and my team to migrate our projects to RTL. Check my article: dev.to/srshifu/migrate-away-from-e...
It has links to the tool you can download and use in your project