testing-library / dom-testing-library

πŸ™ Simple and complete DOM testing utilities that encourage good testing practices.
https://testing-library.com/dom
MIT License
3.26k stars 466 forks source link

#1179: Specify default ontimeout at configuration level #1272

Open Areiser opened 11 months ago

Areiser commented 11 months ago

What:

Make it possible to override the default onTimeout method for all waitFor methods in the config.

Why:

We use the testing library in our organization and would like to print a clear user information that the test ran into a timeout, since we sometimes struggle with flaky tests. Only printing the error leads some users to think that the condition did not time out.

This is my first contribution, I added a test, but if there are any change requests I'll gladly update this PR, as the feature would be very helpful for us.

codesandbox-ci[bot] commented 11 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a1adc197b3bf256f7ab362ea872901a65a3f1648:

Sandbox Source
react-testing-library-examples Configuration
codecov[bot] commented 11 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (a7b7252) 100.00% compared to head (a1adc19) 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1272 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 24 24 Lines 1038 1040 +2 Branches 346 347 +1 ========================================= + Hits 1038 1040 +2 ``` | [Flag](https://app.codecov.io/gh/testing-library/dom-testing-library/pull/1272/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=testing-library) | Coverage Ξ” | | |---|---|---| | [node-14](https://app.codecov.io/gh/testing-library/dom-testing-library/pull/1272/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=testing-library) | `100.00% <100.00%> (ΓΈ)` | | | [node-16](https://app.codecov.io/gh/testing-library/dom-testing-library/pull/1272/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=testing-library) | `100.00% <100.00%> (ΓΈ)` | | | [node-18](https://app.codecov.io/gh/testing-library/dom-testing-library/pull/1272/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=testing-library) | `100.00% <100.00%> (ΓΈ)` | | | [node-20](https://app.codecov.io/gh/testing-library/dom-testing-library/pull/1272/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=testing-library) | `100.00% <100.00%> (ΓΈ)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=testing-library#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

MatanBobi commented 10 months ago

Thanks for this contribution. I'm hesitating whether this is a use-case that should be built-in in the library. Do we believe users will want to configure it on their own? Why not just add a hint that it was caused by a timeout in our codebase and not make it configurable?

timdeschryver commented 10 months ago

@MatanBobi both can be useful. Modifying the message can be helpful to a broader audience (is this a breaking change)? But since we already allow that the message can be overwritten for single cases, I think having a global config for it is OK (as with other config properties). It's also a relative small change that doesn't have an impact to a big area.