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

152
Visualizações
Sigue recibiendo un mensaje de error sobre cómo evitar envolver el código en acto después de envolver el código en acto

Estoy escribiendo una prueba para un componente que usa un formulario de búsqueda. Esto está en search.js e importa un formulario Formik de otro archivo searchForm.js .

He escrito esta prueba unitaria que pasa. Lo he basado en un ejemplo en los documentos de prueba de reacción aquí .

Cada vez que lo ejecuto, aparece este error, lo que me confunde ya que he envuelto todo el código en acto.

 console.error Warning: An update to Formik inside a test was not wrapped in act(...). When testing, code that causes React state updates should be wrapped into act(...): act(() => { /* fire events that update state */ }); /* assert on the output */ This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act
 import React from "react"; import { render, screen, act, fireEvent } from "@testing-library/react"; import Search from "./search.js"; import { ChakraProvider } from "@chakra-ui/react"; test("Search form input", () => { act(() => { const setup = () => { const utils = render( <ChakraProvider> <Search /> </ChakraProvider> ); const searchTermsInput = utils.getByLabelText("search terms input"); return { searchTermsInput, ...utils, }; }; const { searchTermsInput } = setup(); fireEvent.change(searchTermsInput, { target: { value: "23" } }); }); expect(screen.getByLabelText("search terms input").value).toBe("23"); });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Según el comentario anterior, solucionó esto reescribiendo la prueba de la siguiente manera para permitir algunos otros cambios para indicar que suceden en el componente search.js que no formaban parte de esta prueba específica.

 import React from "react"; import { render, screen, act, fireEvent, waitFor } from "@testing-library/react"; import Search from "./search.js"; import { ChakraProvider } from "@chakra-ui/react"; test("Search form input", async () => { act(() => { const setup = () => { const utils = render( <ChakraProvider> <Search /> </ChakraProvider> ); const searchTermsInput = utils.getByLabelText("search terms input"); return { searchTermsInput, ...utils, }; }; const { searchTermsInput } = setup(); fireEvent.change(searchTermsInput, { target: { value: "23" } }); }); expect(screen.getByLabelText("search terms input").value).toBe("23"); // This removes a code not wrapped in act warning triggered by other state events // namely setQuery which is called after adding search term inputs await waitFor(() => screen.queryByText(/Find results/))});
about 4 years ago · Juan Pablo Isaza Relatório
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