---
title: "Discussion on \"Mocking an event handler\" | Hashnode"
description: "Discussion on \"Mocking an event handler\". There are multiple ways to mock an event handler in Jest Testing Framework. I will discuss two different scenarios and further, we will introspect each case.\nScenario1: Component accepts event handler as a prop\nexport const ProductView = ({ product, ..."
url: "https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Mocking an event handler](https://nsblog.hashnode.dev/mocking-an-event-handler?utm_source=hashnode&utm_medium=feed)

There are multiple ways to mock an event handler in Jest Testing Framework. I will discuss two different scenarios and further, we will introspect each case. Scenario1: Component accepts event handler as a prop export const ProductView = ({ product, ...

Oct 28, 2021 · 3 min read · nsblog.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#jest](https://hashnode.com/tag/jest)
-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#testing-library](https://hashnode.com/tag/testing-library)

## Written by

[Navdeep Singh](https://hashnode.com/@navdeep)

@navdeep · Amritsar, India

  
[View profile](https://hashnode.com/@navdeep)

Full Stack Developer - JavaScript

I am a self taught web developer owning experience of 12+ years in web development field.

## Responses 12

Markdown supported · ⌘↵ to post

[Katy Henry](https://hashnode.com/@henrkaty)

[Apr 25, 2024](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/662a0e2248e43fca6c3f51d7)

Your article contains excellent writing. [slope](https://slope.space/) game

[Holiday Maker](https://hashnode.com/@HolidayMaker)

[Feb 14, 2023](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/63eb63fb1a02604287e7dba9)

[chardhamtour.in](https://www.chardhamtour.in/)

[Lorde Laura](https://hashnode.com/@lorde123)

[Jan 12, 2023](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/63bfcb11a54681f9eea762c4)

In this situation, [shellshockerss.co](https://shellshockerss.co/) we cannot mock the event handler because it is internal to the component. However, we know that it calls CartService, which is an ES6 module.

[kashmirtour bazaar](https://hashnode.com/@saim1234)

[Oct 19, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/634fd4af770c93961f03c0f3)

nice \[Kashmir Trip

[Holiday Maker](https://hashnode.com/@HolidayMaker)

[Dec 20, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/634fd4af770c93961f03c0f3#reply-63a18b60a59cad9bdbba1a61)

Hi there! Nice stuff, do keep me posted when you post again something like this! Visit Us: [gujaratexpert.com](https://www.gujaratexpert.com/)

[Otis Jame](https://hashnode.com/@otis123)

[Sep 27, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/6332aa6c4dd8b2344a76af59)

JavaScript is a popular programming language that is often used to build web applications. [amongus2.io](https://amongus2.io/) One of the most common uses for JavaScript is to implement guard clauses in your code.

[Holiday Maker](https://hashnode.com/@HolidayMaker)

[Oct 14, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/6332aa6c4dd8b2344a76af59#reply-6348ec231b098b3c50f27868)

nice post

[Holiday Maker](https://hashnode.com/@HolidayMaker)

[Oct 14, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/6332aa6c4dd8b2344a76af59#reply-6348ecc76461073d09df92dd)

[pilgrimagetour.in](https://www.pilgrimagetour.in/)

[Lorde Laura](https://hashnode.com/@lorde123)

[Sep 27, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/6332a8c867534f360ca968a9)

When you receive an event handler, [nytwordle.io](https://nytwordle.io/) you can use it to perform some action based on the event. For example, you can set a timer to run when the user clicks a button.

[Holiday Maker](https://hashnode.com/@HolidayMaker)

[Oct 14, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/6332a8c867534f360ca968a9#reply-6348ecb76461073d09df92d9)

[kashmirtourpackage.org](https://www.kashmirtourpackage.org/)

[FNAF](https://hashnode.com/@fnafgo)

[Sep 13, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/632049fb6c86d75accc80c74)

Great. You are my favorite author. I always [moviedle](https://moviedle.io/) [quordle](https://quordlegame.io/) love waiting for new articles from you, it's very informative I usually apply to life.

[dy can](https://hashnode.com/@candymika)

[Jul 1, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/62bec2731f580e1c2266361a)

If you want to drive to a lot of locations but are blind on the road, or if you need to go to a lot of places but don't know which direction to go, go to my website right away. [Mapquest driving directions](https://mapdriving-directions.info/) will certainly satisfy you, and they can help you.

[Emily Brown](https://hashnode.com/@EmilyBrown)

[May 6, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/6274b483f24a8e4867f926a3)

You have given useful information here. Nice job done by you. Keep going.

-   [https://www.dissertationhelp.uk/](https://www.dissertationhelp.uk/)

[Alex Juvion](https://hashnode.com/@AlexJuvion)

[May 5, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/62739ea061c9093d16dccf32)

Nice piece of content. I was also searching for such information to provide assignment help on related topic. It’s good to be on this website. - [https://www.qualityassignment.co.uk/](https://www.qualityassignment.co.uk/)

[Jack Ponting](https://hashnode.com/@JackPonting)

[May 4, 2022](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/6272393676abf01feb632f44)

I appreciate you for taking time & sharing such a best post with us. I am impressed with your writing style. Keep it up. Jack, [http://www.qualitydissertation.co.uk/](http://www.qualitydissertation.co.uk/)

[ryan cooper](https://hashnode.com/@ryan987)

[Nov 8, 2021](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/618953e4ce9e5f6dfd785647)

One of the [play online free euchre](https://myeuchre.com/) great article online

[gmmelissa gm](https://hashnode.com/@masiue)

[Oct 29, 2021](https://hashnode.com/posts/mocking-an-event-handler/617a45c5913b6d3f08e17610/comment/617b6ef154e5820289bf901d)

You have given very useful information. Keep it up and keep blogging. I look forward to reading your next post. [slope](https://slopeio.com/)
