How to Mock Only One Function from a Module in Jest

Chak Shun Yu
JavaScript in Plain English
6 min readApr 18, 2021

--

Photo by Oskar Yildiz on Unsplash

Mocking dependencies of your code is one of the fundamental aspects of software testing that allows developers to gain control over data flows and code behaviour.

As a JavaScript testing framework, Jest has an extensive collection of APIs that will make our lives easier and help with mocking dependencies. However, sometimes there are so many options that it’s hard to know all…

--

--

Lifelong learner working as a frontend engineer. React. Self Development and Reflection. Testing. Technical Blogging.