-
Notifications
You must be signed in to change notification settings - Fork 232
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
global configuration setter #812
Comments
Hi @teobler, thanks for taking the time to raise this request. I think this is a good idea and would love to see your contribution here. There has been a previous effort made to add this type of functionality, but it never got merged. Given how long ago that was, it might be easier to start again, but might offer some ideas to implementation for you. As discussed in the previous PR, I think the most straight forward approach would be to have new options introduced to `renderHook’ that sets the defaults for the returned async utils rather than a function to override them globally. The idea is then users can write their own helper around it if they don’t want to set them in every test. I’m not against a global function as well, but it opens up issues around resetting back to the defaults and generally expands the API footprint, which I’m trying to avoid if possible. |
Hi @mpeyper, Thanks for the context sharing, I will take a look about this PR before start it. for global setting idea I'm just thinking if I need to align API style with testing library packages, like react-testing-library: import { configure } from '@testing-library/react'
configure({ asyncUtilTimeout: 10000 }) your concern is reasonable, but we can also add a section in doc to explain how to reset these configuration may like this: import { configure } from '@testing-library/react'
describe('some tests', () => {
beforeAll(() => {
configure({ asyncUtilTimeout: 5000 });
})
afterAll(() => {
configure({ asyncUtilTimeout: 10000 });
})
}) both fine for me, waiting for decision😁 |
Hi @mpeyper any update for your prefer here? |
Hey @teobler, sorry I missed the "waiting for decision" part of your previous message. Given the release of React 18 now, it looks like this PR will be merged very soon, so if RTL already has this functionality, then I don't think there is much value in us adding it now. Sorry to waste your time and thoughts on it. |
Hi @mpeyper, cool, then this should be fine, and you may posted the wrong link lol. anyway, I will close this issue in this case. |
Yes, thanks. I’ve updated the link now. |
Sorry, now a see the Note about React 18 https://github.com/testing-library/react-hooks-testing-library#a-note-about-react-18-support |
Describe the feature you'd like:
add an exported function for global configuration to override/setup default value.
Why
in some scenarios we may need to setup some config globally, like extend timeout for async utils.
But there is no way for these global setup. We can just set them one by one in each test.
Suggested implementation:
we can maintain a global config to be default value, then we can get default values from this global config instead of setup each function.
Then user can call global config function to override default config or just pass custom params when using a specific function during testing.
the priority will be: custom params > global config
Describe alternatives you've considered:
pass config params in each test.
Teachability, Documentation, Adoption, Migration Strategy:
No migration actions required by users. All the changes should not break any feature for current behavior.
Just adding a new API for setup config globally.
byw, I would have a try to add this feature and document if we decide to add this feature after discuss:)
The text was updated successfully, but these errors were encountered: