False positives handling #50
Unanswered
laialopezz
asked this question in
Q&A
Replies: 1 comment 5 replies
-
Woah! first off didn't even realize discussions existed on this repo! Secondly, based on a quick reading of this: https://testing-library.com/docs/guide-disappearance/#waiting-for-disappearance It appears there's two ways to handle this based on your first test. it('should show the feature button', async () => {
const featureItemButton = await shadowScreen.findByShadowRole('button', { name: featureItemSelector });
expect(featureItemButton).toBeInTheDocument();
});
it('should NOT show any feature button', async () => {
// Wait for the element to exist.
await shadowScreen.findByShadowRole('button', { name: featureItemSelector });
expect(featureItemButton).toBeInTheDocument();
// do stuff to remove the element.
// Wait for element to be removed
// This uses a mutationObserver so may not work. See below for other option.
await waitForElementToBeRemoved(() => shadowScreen.queryByShadowRole('button', { name: featureItemSelector }))
// This one may be slightly less performant according to docs, but should be more accurate.
await waitFor(() => {
expect(shadowScreen.queryByShadowRole('button', { name: featureItemSelector })).not.toBeInTheDocument()
})
}); Let me know if that helps get you unblocked! |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone 😄 !
For some time now I have been wondering how I should asynchronously test elements affected by the
shadowRoot
.For positive cases there is no problem but I wonder what would be the best way to test when an element, for example, has not been rendered in the DOM.
Here I attached is an example of the problem:
The second test I would like to make it fail but I can't find the way because it only renders the
<ShadowRoot>
in the first button.Debugging we also noticed that the
<ShadowRoot>
of the'featureItemSelector'
is not rendered.If I query by
test-id
oraria-label
(which in this case I can't do it because it wouldn't be correct and with thearia-labelledby
I can't do the query) the first test works and the second one fails but that is not the way I want to learn how to test it because I would be adding extra things in my code to make it work...We were able to query the button and make the second test fail properly this way but if we change our custom button selector in the future, this is not going to work:
deepQuerySelector(document, 'our-custom-button-selector[text="featureItemButton"]');
Has anyone had the same problem or have any idea?
Thank you very much in advance!
Beta Was this translation helpful? Give feedback.
All reactions