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

128
Vistas
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
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