Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!