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

126
Views
How to test react component with setState in react testing library with Typescript

I have two components in typesciprt. The parent component creates the state and passs the state and setState to the child component and the child component receives this setState.

parent.tsx

function TestParent():JSX.Element {
  const [testResult, setResult] = useState<IResult | null>(null)
  return (
    <TestChild setResult={setResult}/>
  )
}

child.tsx

interface IProps {
  setResult: Dispatch<SetStateAction<IResult | null>>
}

function TestChild(props: IProps): JSX.Element {
  ...
}

When I test child.tsx on child.test.tsx, it says setResult is missing:

test('render component correctly', () => {
  render(<TestChild/>
  ...
}

How should I pass the missing setResult attribute to pass the typescript check?

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!