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

global configuration setter #812

Closed
teobler opened this issue Mar 28, 2022 · 7 comments
Closed

global configuration setter #812

teobler opened this issue Mar 28, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@teobler
Copy link

teobler commented Mar 28, 2022

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:)

@teobler teobler added the enhancement New feature or request label Mar 28, 2022
@mpeyper
Copy link
Member

mpeyper commented Mar 29, 2022

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.

@teobler
Copy link
Author

teobler commented Mar 29, 2022

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😁

@teobler
Copy link
Author

teobler commented Mar 31, 2022

Hi @mpeyper any update for your prefer here?

@mpeyper
Copy link
Member

mpeyper commented Mar 31, 2022

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.

@teobler
Copy link
Author

teobler commented Mar 31, 2022

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.

@teobler teobler closed this as completed Mar 31, 2022
@mpeyper
Copy link
Member

mpeyper commented Mar 31, 2022

Yes, thanks. I’ve updated the link now.

@douglasjunior
Copy link

douglasjunior commented Apr 11, 2022

How about of React Native future?

React Native projects dont use "@testing-library/react" or "@testing-library/dom", but use "@testing-library/react-native" and "@testing-library/react-hooks".

Sorry, now a see the Note about React 18 https://github.com/testing-library/react-hooks-testing-library#a-note-about-react-18-support

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

No branches or pull requests

3 participants