How to force fail a test in Cypress.io

You can just throw a JavaScript Exception to fail the test: throw new Error(“test fails here”) However, in your situation, I would recommend using the .should(‘not.exist’) assertion instead: cy.contains(“Sorry, something went wrong”).should(‘not.exist’)

What is the difference between using `react-testing-library` and `cypress`?

You’ve answered your question in the first line. If you want to test your React app end-to-end, connected to APIs and deployed somewhere, you’d use Cypress. react-testing-library‘s aimed at a lower level of your app, making sure your components work as expected. With Cypress, your app might be deployed on an environment behind CDNs, using … Read more

Error trying to get attribute from element in Cypress

invoke() calls a jquery function on the element. To get the value of an input, use the function val(): cy.get(‘input’).invoke(‘val’).should(‘contain’, ‘mytext’) This is not the same as getting the value attribute which will not update with user input, it only presets the value when the element renders. To get an attribute, you can use the … Read more

How do you check the equality of the inner text of a element using cypress?

I think you can simplify this. Assuming you have HTML that looks like this: <div data-test-id=”Skywalker,Anakin”> <div class=”.channel-name”>Skywalker,Anakin</div> </div> You can write your assert like this: cy.get(‘[data-test-id=”Skywalker,Anakin”]’).should( “have.text”, “Skywalker,Anakin” ); This passed for me and if I modified the HTML to Skywalker,Anakin 1 it failed as you would expect. Cypress uses the have.text to look … Read more

Cypress does not always executes click on element

For those who are using cypress version “6.x.x” and above You could use { force: true } like: cy.get(“YOUR_SELECTOR”).click({ force: true }); but this might not solve it ! The problem might be more complex, that’s why check below My solution: cy.get(“YOUR_SELECTOR”).trigger(“click”); Explanation: In my case, I needed to watch a bit deeper what’s going … Read more