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

247
Vistas
Can you mock functions to get code coverage in react / jest / react testing library

Is it possible to mock function in Jest / React / React testing library to get code coverage.

A simple example:

import React from 'react';

interface NewProps {
    children: React.ReactNode;
}

const handleClick = () => alert('hello');

const New: React.FunctionComponent<NewProps> = (props: NewProps) => {
    return (
        <h1 className="heading">{props.children}</h1>
        <button onClick={handleClick()}>Click</button>
    )
}

export default New;

So for example say I wanted to get coverage for the handleClick function, would I need to mock it?, I say this because some methods I have, are not as simple as this and to test them I was thinking of mocking the function, would that get the coverage?

about 4 years ago · Santiago Gelvez
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