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

Cannot test that a component throws an error #16635

Closed
JessicaSachs opened this issue May 22, 2021 · 3 comments
Closed

Cannot test that a component throws an error #16635

JessicaSachs opened this issue May 22, 2021 · 3 comments
Labels
CT Issue related to component testing type: enhancement Requested enhancement of existing feature

Comments

@JessicaSachs
Copy link
Contributor

JessicaSachs commented May 22, 2021

Current behavior

Cannot test that a component throws an error. Always fails the test because Cypress has no .catch method.

Desired behavior

Can test a component throws an error

Test code to reproduce

import { mount } from '@cypress/react'

it('throws', (done) => {
  cy.on('uncaught:exception', (err, runnable) => {
    expect(err.message).to.include('Expected to throw')
    done()
    return false
  })

  const MyComponent = () => {
    const throwError = () => throw new Error('Expected to throw')
    return <div onClick={ throwError }>Click me to throw</div>
  }

  mount(<MyComponent></MyComponent>)
    .get('div')
    .click()
})

Versions

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

Any news on this?? Really effecting how we are working on an external component package.

@rockindahizzy
Copy link
Contributor

@ilovegithub2 could you provide an example of a component that would require this functionality?

@rockindahizzy rockindahizzy added type: enhancement Requested enhancement of existing feature ct-core labels Dec 9, 2022
@lmiller1990
Copy link
Contributor

This should be working correctly post #23916 merging.

If not, please open a new issue with a minimal reproduction.

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: enhancement Requested enhancement of existing feature
Projects
None yet
Development

No branches or pull requests

4 participants