Skip to content

Migrate from `react-test-renderer` to `@testing-library/react`

Warren Gifford requested to merge tr/react-test-render-refactor into main

Created by: umpox

Migrates all of our simple React Test Renderer tests to use React Testing Library

Part of https://github.com/sourcegraph/sourcegraph/issues/24986

This was originally going to be a series of issues to assign to GitStart, but I realised that the vast majority of these tests could be migrated with some find+replace magic.

For now, it is intentional just to replicate the existing behavior. Over time, we want to improve these tests to test more than just snapshots

Changes:

  • Migrates all test files that just rely on react-test-renderer and toJSON to render snapshots
  • Removes some unnecessary component mocks to make our snapshots closer to the actual created DOM

Benefits:

  • These snapshots now output the actual created DOM that React produces. This is closer to what the user will use, and ensures that we are not testing implementation details. For example, our snapshots should not fail if we rename a component or a prop. TS can check the correct props are passed, our tests should just test what the user will actually use.
  • We're close to removing react-test-renderer! After the follow up ticket is completed () we can remove this library and work on migrating our enzyme tests to @testling-library/react
  • We get some nice coverage boosts as we mock less components

Note: Hide whitespace changes when viewing the diff, it'll be painful otherwise!

Updated usage: image

Merge request reports

Loading