Imagine I have the following simple html:
const inEl = document.querySelector("input")
const buttonEl = document.querySelector("button")
inEl.oninput = (() => {
buttonEl.remove()
setTimeout(() => {
document.body.appendChild(buttonEl)
}, 100)
})
.b {
background: blue;
}
<input>
<button>weee</button>
As you can see, as someone types in the input, the button is temporarily removed from the DOM. I'd like to add a cypress test that checks that the button is NOT removed from the dom (so it would need to fail for the above scenario).
It seems simple enough, but because cypress is so good at waiting for things to appear, I'm not totally sure how to write this test.
It feels like what I need is a way to throw an error if a cypress command does pass. Something like
cy.get("input").type("hello")
cy.get("button").should("not.exist") //if this passes then throw an error!
Any help on how to do this seemingly simple thing would be appreciated. Thanks!