-
Notifications
You must be signed in to change notification settings - Fork 75
testing components using hooks and timeout #514
Comments
Hi @dadamssg, Did you get this question answered? |
I'm pretty sure I saw that this was resolved elsewhere. |
@kentcdodds I think this is still not resolved. And my test here: If I comment out the lines that enable jest fake timers the test fails. |
Hey @kentcdodds I found a workaround. The solution is to run |
I think I was able to produce a simple yet complete demo of continuous, asynchronous polling using @erezrokah 's workaround: https://github.com/mamachanko/continuous-asynchronous-polling-with-react-hooks |
I can still reproduce this issue on [email protected] This test fails with timeout error, the same with waitForElement():
But if I use jest.useRealTimers() it works as expected:
Also lets to move this issue to dom-testing-library repository because it is the first place where people will search. |
I have a really simple slideshow class component i'm trying to convert to hooks to learn how to use and test them but failing. Was hoping you could point me in the right direction.
The class version's test pass while the hook version's test fails with:
I'm using
setTimeout
instead ofsetInterval
because I want the user to able to advance to the next slide on click and have the 'interval' reset so that slide gets the full display time. I think I'm doing the recommended method of setting a state value to control when the effect is called.If I remove jest's fake timers, the tests pass but i don't want the tests to wait the full interval time.
I'd create a codesandbox but codesandbox doesn't support jest.useFakeTimers().
Can you spot if i'm doing something wrong?
The text was updated successfully, but these errors were encountered: