Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make wrapper to render configuration available at the global level #1222

Open
crizzis opened this issue Jul 7, 2023 · 3 comments
Open

Make wrapper to render configuration available at the global level #1222

crizzis opened this issue Jul 7, 2023 · 3 comments
Labels

Comments

@crizzis
Copy link

crizzis commented Jul 7, 2023

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.

@nickserv
Copy link
Member

nickserv commented Sep 13, 2023

While I'd normally recommend custom hooks, I see your point about difficulty refactoring. We're already considering a reactStrictMode option for DTL's configure API, so I think this would be worth prototyping after it's done as it also changes how the render wrapper option works. In the future we could use the same DTL option in our other component framework adapters.

@nickserv nickserv added enhancement New feature or request needs investigation labels Sep 13, 2023
@eps1lon
Copy link
Member

eps1lon commented Sep 16, 2023

The solution here is a custom entrypoint instead of a configuration. The current ones are more subject to being really global but a wrapper really isn't. It's highly subjective to the kind of test and app you test and I don't believe this should automatically leak into all tests.

Instead, stop importing from @testing-library/react and use ~/my-testing-library that uses a custom wrapper by default.

We keep this open for tracking but there is a high bar to implement this. "It's convenient" is not sufficient here.

@crizzis
Copy link
Author

crizzis commented Sep 16, 2023

Yes, those are two sides of the same coin:

On one hand:

It's highly subjective to the kind of test and app you test and I don't believe this should automatically leak into all tests.

On the other:

This would help capture bugs when this context layer has an adverse effect on the behaviour of the component under test.

But, I reckon, as long as the global config is optional, you would be welcome to choose your own poison.

However, I understand the complexity argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants