Skip to content

docs(frontend): Note that tests should render a component, not a renderFoo() helper - #19570

Merged
ryan953 merged 2 commits into
masterfrom
ryan953/rtl-no-render-helper
Sep 22, 2026
Merged

ryan953 merged 2 commits into
masterfrom
ryan953/rtl-no-render-helper

Conversation

@ryan953

@ryan953 ryan953 commented Sep 22, 2026

Copy link
Copy Markdown
Member

Adds a tip to the "Using React Testing Library" page: render the component under test, rather than wrapping render() in a local renderFoo() helper.

The helper is common in getsentry/sentry specs and hides the JSX from every test that calls it, so a reader has to go find the helper before an it() block makes sense. Each file also invents its own name and argument shape for the same idea. The tip shows the ExampleFoo component shape we want instead, and sits with the other tips on the page.

It calls out the part that actually breaks: rerender takes an element, so with a helper the call site no longer controls what is rendered. Passing a different root component type to rerender remounts the tree and silently drops the state the test was checking. That is not a hypothetical — converting 42 spec files in getsentry/sentry#125144 surfaced exactly this in two tests.

The tip also names what is not this pattern, so it does not read as a ban on all test helpers: a helper that only registers MockApiClient mocks, or one that takes the element to render as a parameter, is fine as it is.

Related

…erFoo() helper

A local renderFoo() helper hides the JSX from every test that calls it, and it breaks rerender, which takes an element. The tip sits with the other RTL tips and shows the Example component shape we want instead.
@vercel

vercel Bot commented Sep 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
develop-docs Ready Ready Preview Sep 22, 2026 8:20pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-docs Ignored Ignored Preview Sep 22, 2026 8:20pm UTC

Request Review

@github-actions github-actions Bot added the Priority: Needs Triage The PR description is missing valid priority information label Sep 22, 2026
@ryan953
ryan953 marked this pull request as ready for review September 22, 2026 20:17
The tip was longer than the tips around it. A generic Widget makes the same point in half the space.
@ryan953
ryan953 requested a review from a team September 22, 2026 20:17
@github-actions

Copy link
Copy Markdown
Contributor

Please update the IS YOUR CHANGE URGENT? section of the PR description:

  • Select exactly one option.
  • If you selected an urgent or other deadline, provide the date as YYYY-MM-DD.

This information helps the Docs team prioritize your review.

@ryan953
ryan953 merged commit 988f6f1 into master Sep 22, 2026
22 checks passed
@ryan953
ryan953 deleted the ryan953/rtl-no-render-helper branch September 22, 2026 20:52

This branch was successfully deployed

1 active deployment
Preview – develop-docs 4721daac Deployed Sep 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: Needs Triage The PR description is missing valid priority information

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants