WhoBuilt

Testing Library Meets React Native

Oct 21, 2020· 32 min· 546 views·Watch on YouTube

Speakers

Callstack software engineers Maria Marchenkova and Michał Pierzchała speak at React Native EU 2020 about the development and consolidation of Testing Library for React Native.

Why earlier testing approaches fell short

Marchenkova compares React Test Renderer and Enzyme, two common approaches before 2018. Test Renderer enabled snapshots and tree queries, while Enzyme's shallow rendering made it difficult to test user behavior and encouraged direct access to component state and methods.

Testing Library brings tests closer to user behavior

Marchenkova describes React Testing Library's guiding idea: tests should resemble how people use software, focusing on visible UI rather than implementation details. She demonstrates rendering a component, clicking a button, and waiting for a greeting to appear, using queries based on text and accessibility roles.

Building React Native Testing Library

React Native runs JavaScript without a browser DOM, so the web library could not be reused directly. Callstack built React Native Testing Library as a thin layer over React Test Renderer, initially including some shallow and implementation-focused queries to help teams migrate from Enzyme.

Two libraries and a path to consolidation

Marchenkova recounts how Native Testing Library emerged with a closer fit to Testing Library principles, while the two projects differed on APIs, goals, and ownership. After early discussions failed to produce a merger, React Native Testing Library v2 removed shallow rendering, added APIs such as `within` and `findBy`, and discouraged unsafe queries. Kent C. Dodds later proposed deprecating Native Testing Library and adopting Callstack's project as the official `@testing-library/react-native` package.

Lessons from maintaining an open-source library

Marchenkova says to focus on users, keep improving a product you believe in, and make maintenance manageable. She credits the library's thin layer over stable React tools with helping it survive React Native changes, and notes that company support for open source can also bring community recognition.

Takeaways

  • Test what users can see and do instead of relying on component internals.
  • Accessibility roles and visible text make queries reflect real user interactions.
  • A thin layer over stable tools can reduce the maintenance burden of an open-source library.
  • Plan migrations carefully, especially when removing APIs or consolidating packages.
  • Company support can sustain open source work, while business interests can shape project decisions.

Mentioned in this talk

Search inside this talk

What was claimed 11

Show all 11 facts

Related talks