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

239
Vistas
test coverage uncovered for testing if statement in react

I have a form submit event in React, then it redirect to a url using history

const handleFormSubmit = (e) => {
    e.preventDefault();
    if (query) history.push(query); //here is uncovered
  };

<Form onSubmit={handleFormSubmit}>

I'm testing it using react-testing-library

it("should type input and redirect if submitted", async () => {
    fireEvent.change(screen.getByPlaceholderText(/your name/i), {
      target: { value: query },
    });
    await screen.findByDisplayValue(query);
  });

  it("should submit the search form", async () => {
    fireEvent.click(screen.getByText(/submit/i));
    expect(await history.location.pathname).toBe("/" + query);
  });

The test is passing, but the coverage report in jest show history.pushState(query) is uncovered. I guess it's because of the if statement?

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