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

129
Vistas
How to call test this callback that sets state in React Enzyme Jest

Let's say I need to test this Component. It gets state and setter for it trough props. How should test look like, I wasted 4 hours trying to figure it out but nothing really works.

Component.jsx

export function Component({ isShowing, setShow }) {
  return (
    <>
      <button
        onClick={() => {
          setShow(!isShowing);
        }}
      >
        Toggle
      </button>
      {isShowing && <h1>Showing</h1>}
    </>
  );
}

This is something I was thinking about but it doesn't pass.

Component.test.js

import Enzyme, { mount } from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new EnzymeAdapter() });

const mountSetup = (props = {}) => {
  return mount(<Component {...props} />);
};

const defaultProps = {
  isShowing: false,
  setShow: () => {},
};

describe('Component works as expected', () => {
  test('Component toggles ', () => {
    const wrapper = mountSetup(defaultProps);
    // expect(wrapper.prop('setShow')).toBeTruthy();
    wrapper.find('button').simulate('click');
    expect(wrapper.find('h1').text()).toBe("Showing")
    wrapper.unmount();
  });
});
about 4 years ago · Juan Pablo Isaza
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