-
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
Type error triggerd by afterEach hook: Cannot read property 'selector' of undefined #9207
Comments
Yeah, this seems like unexpected behavior to me. This looks to be a regression from 5.3.0 that was introduced in this PR: #8612 It seems in this case that the Reproducible example
<html>
<body>
<a href="http://www.cypress.io">www.cypress.io</a>
</body>
</html>
describe('Uncaught exception in afterEach() hook.', () => {
afterEach(() => {
cy.wrap('a[href=\'http://www.cypress.io\']')
.should('not.have.text', 'www.cypress.io')
})
it('Failing test.', () => {
cy.visit('index.html').then(() => {
expect(false).to.be.true
})
})
}) 5.2.05.3.0 |
I could reproduce the bug. But it made me think that it's not related with #8612. Because this issue has 2 problems:
But before trying to fix this issue, I want to ask this question. When should we add assertions inside |
It seems reasonable to add assertions to I tracked down this issue to #8612 - the issue does not occur in the commit prior to that PR. The assertion has always logged 4 times (not introduced in the PR), but yeah I think that is not what should be happening. The bug is that the failed assertion in the test body doesn't fail the test - and log the reason the test failed as |
Moving on to the That's why I asked if it is not an anti-pattern. Asserting is the purpose of And I learned that it was called 4 times in And just ignoring the failure inside As I said above, the job of |
About having assertions in the |
@tzolnai Then, I think we need to show afterEach error message rather than the failed test, right? |
@sainthkh: I think this conversation went off a bit. This issue is about the type error and not about whether |
Currently, I'll submit a PR that bypasses this type error. It seems that we should treat bypassing the type error and making |
As discussed in #9256, #9207 partially solved this problem by throwing error when But it doesn't bring back the before-5.3.0 behavior. To solve this problem, we need to do 2 things:
|
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
I experienced an issue with
afterEach()
hook. Sometimes when theafterEach()
should fail on an assertion it fails, but with an exception coming from cypress code.Current behavior
Cypress fails with a type error, instead of a normal test failure.
Desired behavior
We should not experience a type error in this case.
Test code to reproduce
It somehow related to that the actual test case is failing too, without it I can't see the same issue.
I see the following error in the log when I try to run this test in headless mode:
Versions
cypress version: 5.5.0
browser: chromium 78.0.3904.108
OS: openSUSE Leap 15.0
The text was updated successfully, but these errors were encountered: