enroberte
enroberte

Reputation: 55

Testing state of a button

When I click a button via cy.get('#numberOfFetusOne').click() its class changes to selected. How can I validate this change of the class? If I try to get a class with cy.get I get an error: Expected to find element: gpx-16 i1-regular gpu-selected, but never found it.

<gpu-button-option _ngcontent-udx-c111="" id="numberOfFetusOne" value="Singleton" class="gpx-16 i1-regular" _nghost-udx-c95=""> 1 </gpu-button-option>
<gpu-button-option _ngcontent-udx-c111="" id="numberOfFetusOne" value="Singleton" class="gpx-16 i1-regular gpu-selected" _nghost-udx-c95=""> 1 </gpu-button-option>

Upvotes: 0

Views: 425

Answers (1)

Alapan Das
Alapan Das

Reputation: 18650

You can add a should assertion for this.

cy.get('#numberOfFetusOne').should('have.class', 'gpu-selected')

Upvotes: 2

Related Questions