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

148
Vistas
How to get to the states within my function component in React for an integration test?
import {render,screen,cleanup,waitFor, fireEvent}from "@testing-library/react"
import { BrowserRouter} from "react-router-dom";
import Header from "../Header";

const CustomRender = () =>{
   return (
    <BrowserRouter>
        <Header/>
    </BrowserRouter>
   )
}
describe("Header", ()=>{
    describe("icon should either display or hide nav bar", ()=>{
        test("should render nav visible",()=>{
            render(<CustomRender/>)
            const icon = screen.findByRole("div", {name : /menu__nav-icon__reactIcon/i})
            fireEvent.click(icon)
            const nav = screen.findByRole("ul", {name : /nav/i})
            waitFor(()=>expect(nav).toBeInTheDocument())
        })
    })
    
})

As you can see my Header component doesn't have any props. So the purpose here is simple, inside the component there is a boolean state which I could use to get my test work fine.

Basically when icon is clicked I want to make sure the boolean state is true and then I expect nav is in the document or is visible, I have to check which one is better.

So my question is how, from the Header.test.js file, to get to that boolean state within my function component?

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