cypress: Cypress Doesn't Fail Test on Range of Unhandled Exceptions
Current behavior:
Cypress passes test, although the HTML page contains a script in the head, here’s the full markup:
<html lang="en">
<head>
<title>Hello World</title>
<script>
(async function () {
window.onerror = (_a, _b, _c, _d, err) => {
throw new Error('new err from within onerror');
throw err;
};
setTimeout(() => { throw new Error('original error'); });
throw new Error('regular promise rejection');
})()
</script>
</head>
<body>
<div>
<h1>This should fail...</h1>
</div>
</body>
</html>
Screenshot

Desired behavior:
Cypress should fail the test if there’s:
- An unhandled promise rejection
- A re-thrown error from within window.onerror
- A new error from within window.onerror
Steps to reproduce:
Setup Cypress in a new repo, serve a static Index.html file with a script in the head like the example I’ve provided. Run the spec and watch it pass…
Versions
Cypress 3.1.4 Electron 59 macOS 10.14.2
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 2
- Comments: 30 (14 by maintainers)
Is there any way to fail a test based on console errors?
Was able to reproduce. Added this test to
cypress-example-kitchensinkapp:Add this to
index.html:I have tried it and confirmed the test finishes too quickly - the error is thrown after the test. We have described this in the blog post https://www.cypress.io/blog/2020/01/16/when-can-the-test-stop/
If you suspect the page throws an error, the simplest way is to add a wait at the end
which fails the test correctly.
@jennifer-shehane is there anything else we can do?
Running 4.0.1 and unhandled rejections are still passing.
any news on this?
I am having the same issue when errors occur inside of a Vue event handler, the error is logged on the console but the test does not fail. Is there any way to Fail a running test from application code?
Hey @andezzat, I have an update on this issue.
Currently, Chrome is the only browser that throws
unhandledrejectionevents instead oferrorevents. Cypress only listens toerrorevents to fail the test. However, in 4.0, we’ve extended Cypress to also listen tounhandledrejectionevents, so be on the lookout for 4.0 release. https://github.com/cypress-io/cypress/issues/2884