How can I run this function, according to the value change of element with if-condition?
assertSwitch(){
cy.get('[data-test="form-switch"]').invoke('attr','value').then(($switchOnOff) =>{
if($switchOnOff == true){
cy.isContain('.item-undefined-switch[data-test="item-undefined-email"]', 'true')
}else{
cy.isContain('.item-undefined-switch[data-test="item-undefined-email"]', 'false')
}
})
}
The function appears to be using Cypress commands to check the value of a switch element with the attribute
data-test="form-switch"
. If the value istrue
, it uses thecy.isContain()
command to check if the text ‘true’ is present in an element with the class.item-undefined-switch
and the attributedata-test="item-undefined-email"
. If the value isfalse
, it checks if the text ‘false’ is present in the same element.To run this function, simply call it within a Cypress test: