testing-library / testing-library/react-testing-library

Make wrapper to render configuration available at the global level

Open
#1,222 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement needs investigation
Dominant language
JavaScript
Stars
19.7k
Forks
1.2k
Avg merge
3d 16h
Merged PRs (30d)
1

Description

Describe the feature you'd like:

When rendering components for test, I often find myself repeating render(ui, { wrapper: TestApp() }) over and over again.

It would be nice to have a possibility to define the wrapper using a global configure(...) call.

By having this in global config, you could ensure that, by default, all the rendered components are tested in the context resembling the onion structure of various wrappers and context providers that they are going to be embedded in in production code anyway. This would help capture bugs when this context layer has an adverse effect on the behaviour of the component under test.

Describe alternatives you've considered:

You could of course define a custom function that does the same for you by wrapping the call to render. However, without the hindsight of defining one upfront, if you've already used the barebones render in hundreds of tests before the need for a wrapper, you need to now refactor all of those tests :(

Teachability, Documentation, Adoption, Migration Strategy:

No migration needed as this would be backwards-compatible in terms of the configure API.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing configure(...) API and render(...) entry points, then review tests covering render options and configuration behavior. Define how a globally configured wrapper combines with or is overridden by a per-call wrapper, and add tests showing the global wrapper applies without breaking existing render usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.