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

245
Views
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
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!