Skip to content

Implement renderHook #869

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

Closed
thymikee opened this issue Nov 28, 2021 · 8 comments
Closed

Implement renderHook #869

thymikee opened this issue Nov 28, 2021 · 8 comments

Comments

@thymikee
Copy link
Member

thymikee commented Nov 28, 2021

Describe the Feature

See testing-library/react-testing-library#991 for details

Possible Implementations

Copy the implementation from RTL.

@MattAgn
Copy link
Collaborator

MattAgn commented Dec 7, 2021

Hi @thymikee! I'd be glad to help on this, I'll make a PR shortly

@pierrezimmermannbam
Copy link
Collaborator

Hi @thymikee, @MattAgn told me he finally couldn't find time for this so I made a pr

@manugo-dev
Copy link

Hello there!

How about the waitForNextUpdate function ? Im trying to figured out how to upgrade my tests to be compatible with the new renderHook on the react-testing-library

image

@pierrezimmermannbam
Copy link
Collaborator

@manugo-dev you should be able to use react-native-testing-library's waitfor instead. If I'm correct, being able to use the async utils from the library instead of utils such as waitForNextUpdate that are a bit too focused on implementation detailswas one of the reasons why it was decided to implement a renderHook equivalent on react-native-testing-library and on react-testing-library's side

@mdjastrzebski
Copy link
Member

Closing as implemented by #963.

@kylebake
Copy link

kylebake commented Aug 1, 2022

@manugo-dev you should be able to use react-native-testing-library's waitfor instead. If I'm correct, being able to use the async utils from the library instead of utils such as waitForNextUpdate that are a bit too focused on implementation detailswas one of the reasons why it was decided to implement a renderHook equivalent on react-native-testing-library and on react-testing-library's side

Am I correct in assuming that what you mean is there's no built in way to waitFor the return values of hooks directly anymore and we will need to always test the consumers of the hooks and have to waitFor elements to show/hide based on the values of the hook?

Edit: ignore this comment, moving discussions over to #1030

@AugustinLF
Copy link
Collaborator

I believe what they mean is that you can simply use waitFor to wait for the value of the hook to change. Something like that:

import {waitFor, renderHook} from '@testing-library/react-native'
import myHook from './myHook'

test('myHook', async () => {
  const {result} = renderHook(() => myHook())
  await waitFor(() => {
    expect(result.current).toBe(1)
  })
})

@kylebake
Copy link

kylebake commented Aug 2, 2022

Yes that's how the other libraries typically work with waitFor, but that's not the functionality I'm seeing with RNTL. I opened a separate issue here that I'm going to be looking more into

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

No branches or pull requests

7 participants