Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
How to catch such an error with jest and testing-library/react

Simply saying I want to assert clicking on this button without onClick prop will result in an error(I know this is a silly case but this is just a rough simplification). But unfortunately I cannot catch this error, no matter how I tried.

The pseudocode looks like this:

Element.js:

const Element = ({ onClick }) => (
<button onClick={() => onClick('test')}>Test</button>)
);

Element.test.js

it('triggers on click callback', () => {
    const wrapper = render(<Element />);

    expect(userEvent.click(wrapper.getByTestId('test'))).toThrowError();
  });

I receive 3 console.error statements: "console.error Error: Uncaught [TypeError: onClick is not a function]"

and a

   expect(received).toThrowError()
    Received function did not throw

This doesn't make much sense to me. Please help me find a solution or at least clarify what is happening

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda