

The is shown with when the input is no longer pristine (user types something) nor valid (less than 1).When the user types in the input we fire the function and set and `` to the user’s input.On the initial creation of this functional component, we assign and with the `` hook.Here’s what our component will look like: Our Component We’ll create some basic tests for asserting form inputs. The TL DR is that RTL does not include a lot of the utilities that Enzyme has (such as and) because theyĪre things which users of your component cannot do, so your tests shouldn’t do them either.

Dodds has a comprehensive article about his dislikes with shallow rendering in Enzyme. If you’d like an in-depth analysis, Kent C. Unlike Enzyme, RTL will test DOM nodes instead of component instances if said component is related to rendering. As such, when your components are refactored in the future (to change implementation but not functionality), your tests do not break and your time isn’t spent fixing it. RTL structures your test in a way that doesn’t include the implementation details of your components. How is RTL different than other frameworks like Enzyme?
Functional testing software#
The more your tests resemble the way your software is used, the more confidence they can give you. React-testing-library (RTL) is a testing framework created by Kent C. I eventually landed on react-testing-library. I tried a handful of libraries and methods like Enzyme, react-test-render, and snapshot testing. This is the first in a series of articles that will help you build a solid foundation for testing React components.Īt the beginning of the year, I set a goal to improve my code quality by focusing more on testing.
