-
Notifications
You must be signed in to change notification settings - Fork 91
findByRole not working properly after element is present in DOM #159
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
Comments
Hey Tim, I made the modification as you pointed but that still makes the test fail. I'm supposing that's maybe a "limitation" of What I did for now is to use |
It could be that I misread the original issue.
My advice is to use What I do think is that you will have to re-query for the element, instead of using the reference: - await expect(holderHtmlElementRef).resolves.toBeInTheDocument(); // fail
+ await expect(screen.findByRole('textbox', { name: /holder/i })).resolves.toBeInTheDocument(); This could be a bug on our side tho, I haven't tested this with another testing library variant. I hope this helps. |
I tried this with RTL and the behavior is the same. To not repeat the query you can wrap it inside a factory method: const holderHtmlElementRef = () => screen.findByRole('textbox', { name: /holder/i });
await expect(holderHtmlElementRef()).rejects.toThrow(/Unable to find/i);
await userEvent.type(numberHtmlElementRef, '5353107424870314');
await expect(holderHtmlElementRef()).resolves.toBeInTheDocument(); |
Thanks for the explanation :) |
I have a markup that some elements visibility depends on a condition. Something like this:
So, the fields
holder
,expiry
andcvv
are visible oncenumber
is valid, but the tests keep failing. I noticed that if I query it again, usinggetByRole(...)
to check if it's present in document, it works, but shouldn'tfindByRole(...)
works in this case?The text was updated successfully, but these errors were encountered: