Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda