Expect is failing but test is passing in cy.on confirm & alert message
See original GitHub issueI wanted to test my content of the confirmation message but it seems that even if my test fails my case passes
it('Should Get Confirm Message', () => {
cy.get('.button')
.click();
cy.on('window:confirm', str => {
expect(2 + 2).to.equal(5);
})
})
The issue seems to be similar to https://github.com/cypress-io/cypress/issues/3497 and https://github.com/cypress-io/cypress/issues/2413
But their solution does not work for me.
The issue persists for window:alert
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Expect is failing but test is passing in cy.on confirm & alert ...
What this means is that the window:confirm may be invoked after the test has already finished (which seems to be your case ---...
Read more >Testing Browser Alerts, Confirmations, and Prompts with ...
Confirmation : triggers a message dialogue but provides two actions allowing the user to accept or cancel the dialogue, both closing after an ......
Read more >When Can The Test Stop? - Cypress
A test should not stop until all assertions have passed. We can modify our test to "wait" for the expect to execute, and...
Read more >Cypress Metaprogramming | Better world by better software
I suggest encoding that the test is expected to fail and the the expected error message in the test title. We have access...
Read more >How to handle web Alerts in Cypress? How to ... - YouTube
How Cypress handles Alerts in web apps?+ How to verify text message in alert box?+How to automate Confirm pop up through Cypress?
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here’s my take without using state:
Here is an example waiting for the confirm to have been called before finishing the test (the code calls
window.confirm
1 second after the click), see https://github.com/cypress-io/cypress-test-tiny/tree/confirm-after-testWithout waiting
With waiting
When the test passes (comment out the false assertion, or change it to pass), then all is good
When the assertion is false, the test correctly fails (even if the error message claims the assertion was thrown from the application code)
I think all assertions that pass or fail AFTER the test has finished should have a warning icon ⚠️ next to them in the Command Log. On click, the DevTools should print a message in the console, explaining