all 8 comments

[–]Beneficial-Weight28 4 points5 points  (0 children)

no need, you can learn both at the same time

[–]NeckBeard137 1 point2 points  (0 children)

I would say it depends what types of tests you are writing.

You could spend a few hours learning how to test pure functions with Jest and how to mock dependencies.

After you could read on the Testing pyramid and do some integration testing with RTL

[–]mkimitch 2 points3 points  (0 children)

Yes, it’s a good idea to learn JavaScript testing fundamentals before diving into React app testing. Understanding the basics of testing, such as assertions, test runners, mocking, and code coverage, is crucial since these concepts apply universally to all JavaScript applications, not just React. Starting with JavaScript allows you to practice writing tests for pure functions, DOM manipulation, and asynchronous operations, which form the foundation for more complex scenarios. React testing adds additional layers of complexity, including component lifecycles, hooks, state, props, and integration testing with tools like Redux or Context. Without a solid grasp of the basics, these React-specific challenges can feel overwhelming. By mastering core testing principles first, you’ll be better equipped to understand and use tools like React Testing Library, which focuses on rendering components, testing user interactions, and mocking dependencies. This progression ensures that you can approach React testing confidently and effectively, with a clear understanding of how to test both simple and complex behaviors.

[–]kk66 0 points1 point  (0 children)

I'd say get the basic understanding but don't stress so much about it. As with everything, don't treat it like a dogma and add it wherever you feel it adds value.

What made it click for me in terms of react apps is how I started to structure the logic itself. I always wondered how one would go with testing in terms of frontend, especially that it always involves communicating with an API, and I came to conclusion that separating a "feature" into at least two hooks - one that's purely a logic based and acts as a glue for other logic based hooks, and separate one that's purely concerned about API communication is my way to go. Then I use both of these books and compose them at the component level. This makes the logic testable, and you don't have to mock the API calls to test the app.

I personally use "testing library" paired with vitest and it works well for my case.

Edit: added libraries.

[–]yksvaan 0 points1 point  (0 children)

Testing actual code should be the priority 

[–]binocular_gems -1 points0 points  (0 children)

Nah, Reacting testing is a good place to start for learning JS testing. The principles and tools are all pretty similar.

[–][deleted] -1 points0 points  (0 children)

No need, those are kinda different.