I
I
Ivan Derbenchenko2021-07-13 17:25:49
React
Ivan Derbenchenko, 2021-07-13 17:25:49

Testing a React Application?

Hello!
I'm new to React, something turns out something doesn't .... not the point. Now I started to deal with React testing, I used jest + enzyme. According to advice from various sources, I don’t use class components, I write on hooks to the maximum.
The problem is that the component testing examples are based on class components, and are not applicable to me, I can’t find anything sensible on this issue.
In the same examples, visual testing was described, according to the type: "the user saw several buttons with such and such inscriptions, clicks on a button with a specific name, the button was pressed."
It seemed to me that testing the application looks a little different ...
I would like to know:

  • Is there really a need to test React if everything can be tested with "eyes"?
  • what libraries do you use when testing?
  • How difficult is it to write a React app/website with TDD?
  • perhaps you know sources with examples of testing React based on functional components?

A similar question was asked three years ago on habr'e
I would be grateful, thanks!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Lewandowski, 2021-07-13
@Mr_FabiozZz


Is there really a need to test React if everything can be tested with "eyes"?

Everything will not work out with your eyes if the application is larger than tushka.

what libraries do you use when testing?
perhaps you know sources with examples of testing React based on functional components?

React Testing Library .
You also need to consider that a web application is not only React, but also stores, asynchronous logic and all that.

E
Egor Zhivagin, 2021-07-14
@Krasnodar_etc

Is there really a need to test React if everything can be tested with "eyes"?

Yes, you can't test everything with your eyes. Have you ever had cases when you correct something in one place, and an error appears because of this in another? Unit testing protects against such errors
what libraries do you use when testing?

jest + enzyme
How difficult is it to write a React app/website with TDD?

IMHO, tdd is not well suited for unit tests. Much better for end-to-end
perhaps you know sources with examples of testing React based on functional components?

I don't really understand, what's the difference? The principle of testing is the same, the set of tools is the same, ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question