-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught (in promise) TypeError doesn't cause test to fail #4998
Comments
I confirm that behaviour. Cypress.on('fail', (error, runnable) => {
skipAllTests = true;
throw error;
}) function deleteElements(name, deleteFunc) {
isContain(name).then(el => {
for (let i = 0; i < el.length; i++) {
isContain(name)
.eq(0)
.click({ force: true });
deleteFunc();
cy.wait(1000);
}
});
}
…
cy.route({
method: 'DELETE', url: '/master/locations/*',
onResponse: (xhr) => {
expect(xhr.status).to.eq(expectedHttpStatus);
}
}).as('deleteLocations');
…
deleteElements('TestBla', () => {
cy.wait('@getLocationsDetails');
cy.wait(500);
cy.getElementByDataCypress('btnDeleteLocation').click({ force: true });
cy.get("button:contains('Ja'),button:contains('Yes')").click({ force: true });
cy.wait('@deleteLocations');
}) It does not work in visual test runner and also does not work in Background mode. |
I went all the way back to cypress@2.1.0 and observed the same behavior: test still passes and events do not get triggered. |
@jennifer-shehane Could you confirm this behavior as intended or a defect? It makes for some scary false positives and I need to figure out how to mitigate that. |
@brian-mann Any thoughts on this? I basically can't use the promise pattern in my own support code currently because if there are exceptions in the support code, they don't fail the test. Is that desired? What am I doing wrong? |
might wanna try using the Cypress promise which wraps bluebird promises but should be chained off cy. |
The correct way how to write this is: describe('how to fail', function () {
it.only('should fail', function () {
cy.visit("http://google.com")
const doTheThing = () => {
return new Promise((resolve) => {
resolve({done: true})
})
}
// see the cy.wrap here
cy.wrap(doTheThing()).then((obj) => {
const test = obj.badAttribute.reallyBad
console.log(test)
cy.log(test)
})
})
}) Otherwise, your test ends before |
Is this a duplicate of #2487? |
Cypress only waits for it's own enqueued commands to finish before passing the tests. So after the visit succeeds, there are no more Cypress commands enqueued - so it passes. As mentioned by @trejjam, you'll want to put your promise in a |
Steps to reproduce:
This will throw this exception:
The problem is this is considered a pass in cypress:
Current behavior:
Cypress tests don't fail when there's an exception within Promise
Desired behavior:
Cypress test should fail if there's an unhandled exception in my test code. Right?
Versions
cypress==3.4.1
Note: I've added these in my support file and the debugger never breaks at these events for the above test:
The text was updated successfully, but these errors were encountered: