When attempting to use the screen feature from a test library in my unit tests for a component, I encountered an issue with verifying whether a button is disabled based on the JSX generated from the component. I attempted to use the toBeDisabled
method but received the error message:
Received element is not disabled:
ref:
// test.ts
const button = screen.getByText('I am action Button')
expect(button.closest('div')).toBeDisabled();
// screen.debug()
<body>
<div>
<div class="menu is-disabled">
<a class="bar-button">
<span class="bar-label">
I am action Button
</span>
</a>
</div>
</div>
</body>