Skip to content
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

Problems with cypress 7.5.0 & @cyprss/react and 'uncaught:exception' handling #16868

Closed
glomotion opened this issue Jun 9, 2021 · 3 comments
Closed
Labels
CT Issue related to component testing type: bug

Comments

@glomotion
Copy link

glomotion commented Jun 9, 2021

Current behavior

REPRO: https://github.com/glomotion/cypress-bug-repro

When running headless tests WITH coverage enabled, cypress errors out (npm run test)

Screen Shot 2021-06-09 at 6 13 39 pm

However when running headed or with coverage DISABLED, cypress tests pass as they should (npm run test:fast or npm run test:watch)

Screen Shot 2021-06-09 at 6 17 08 pm

Desired behavior

Tests should pass in all modes or fail in all modes 🤪 🤷

Test code to reproduce

REPRO: https://github.com/glomotion/cypress-bug-repro

NOTE: these tests are using 'uncaught:exception' to catch runtime errors, and assert that they are happening correctly. EG:

before(() => {
    Cypress.on('uncaught:exception', () => {
      // returning false here prevents Cypress from
      // failing the test
      return false;
    });
  });

it('should throw error, when a fragment is supplied as children', done => {
    cy.on('uncaught:exception', err => {
      expect(err.message).to.include(ERROR_TEXT);
      done();
      return false;
    });
    mount(
      <AppHeaderBarNavItem testId="nav1">
        <>moo</>
      </AppHeaderBarNavItem>,
    );
  });

Versions

MacOS: 11.4 (20F71)
MacBook Pro (15-inch, 2019)

  "@cypress/code-coverage": "^3.9.6",
  "@cypress/react": "^5.9.1",
  "@cypress/webpack-dev-server": "^1.3.1",
  "cypress": "^7.5.0",
  "cypress-real-events": "^1.5.0",
@glomotion glomotion changed the title Problems with cypress 7.5.0 and 'uncaught:exception' handling Problems with cypress 7.5.0 & @cyprss/react and 'uncaught:exception' handling Jun 9, 2021
@bahmutov bahmutov self-assigned this Jun 9, 2021
@bahmutov
Copy link
Contributor

bahmutov commented Jun 9, 2021

I looked at the situation, something is wrong because when the error is thrown Cypress CT tries to mount the component again causing the problem. You can find my simplified test in https://github.com/bahmutov/double-error-bug

  • npm install
  • npm run test:watch

I am printing the log message before throwing the error

if (
    typeof children === 'string' ||
    isReactFragment(children) ||
    !isChildReactComponent(children)
  ) {
    console.error('App throwing an error')
    throw Error(ERROR_TEXT);
  }

I see the double log message in the console, which is incorrect

Screen Shot 2021-06-09 at 9 44 50 AM

@bahmutov bahmutov removed their assignment Jun 9, 2021
@bahmutov
Copy link
Contributor

bahmutov commented Jun 9, 2021

By the way, we have error message tests for E2E here https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/fundamentals__errors

@lmiller1990 lmiller1990 added CT Issue related to component testing and removed component testing labels Aug 15, 2022
@lmiller1990
Copy link
Contributor

I think we fixed error propagation as part of CT Stack Traces: #23916

Should be 💯 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CT Issue related to component testing type: bug
Projects
None yet
Development

No branches or pull requests

4 participants