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
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 à 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