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
add possibility to configure interval with configure method #1507
add possibility to configure interval with configure method #1507
Conversation
@@ -552,7 +552,7 @@ Defined as: | |||
```ts | |||
function waitForElementToBeRemoved<T>( | |||
expectation: () => T, | |||
{ timeout: number = 4500, interval: number = 50 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed like a mistake based on what is in code (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it is, thanks for fixing that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution @maciekstosio! This looks good to me, you'll need another maintainer's approval before this can be merged.
I'm curious though, why do you think that the 50 ms interval is too long for you?
@pierrezimmermannbam I'm testing two screens, first one checks if the user is logged in, and it moves to another one that fetches data (and displays loader while fetch is in progress).
Now, I had a problem that test failed on second |
@maciekstosio regarding your test case, you should wait only for the first element to be removed, as expect(screen.getByTestId('loading-indicator')).not.toBeOnTheScreen() |
@maciekstosio I am somewhat hesitant on adding this option, as it seems that it's not really related to the root issue you are having. Relying on 10ms grain timing using real timers in test will probably result in flaky tests. The recommended solution would in such case would be to use fake timers, as they over more precise control. Linking to similar DOM Testing Library issue. |
Oh ok I get it. I would agree with @mdjastrzebski that diminishing the interval for this use case may not be the optimal solution. Maybe for this particular use case, if you really want to test both loading states you could use the delay option from |
Yeah, you're right. I had a problem using fake timers, thus I didn't like that approach, but it seems like it was because of |
Alright I'll close that pr for now then |
Summary
Currently, we're able to override the default timeout, but we can't do the same for the interval. For my test cases, 50ms has proven to be too long of an interval, and changing that setting for each case is tedious. I added a possibility to configure the default interval by configure method to solve that.
Test plan
I added tests based on those for interval and timeout.