Replies: 1 comment
-
What do you mean with However, regardless of that, something like this should work, if that's what you mean: const button = screen.getByRole('button', { name: 'Click me' })
expect(button).toBeEnabled()
// perform some action that makes the button disabled
expect(button).toBeDisabled() You do not need to re-query for the button to check that it is disabled. Unless the "perform some action" part causes the button to be re-mounted. That could happen depending on how you render the two different buttons (the enabled and the disabled one). If you render it using different React components, for instance: <div>
{isEnabled ? <EnabledButton /> : <DisabledButton />}
</div> Something like that could cause the button DOM element to be re-mounted instead of updating the same Not sure how much of this is releavant to your question, given that it seems to be tied to this hypothetical |
Beta Was this translation helpful? Give feedback.
-
I want to find out if an element I have already queried for has
aria-selected="true"
. I know that I can doscreen.getByRole("bla", { selected: true })
but what if I already have an element saved to a variable and I want toexpect
that elementtoBeSelected
?The
ariaSelected
field isundefined
which deviates from the behaviour inside the browser, but I suppose that's a shortcoming ofjsdom
?Am I stuck with re-querying for the element and passing
selected: true
into the options?Beta Was this translation helpful? Give feedback.
All reactions