Member-only story
This post documented down my discovery about Jest Matchers toHaveBeenCalled()
function.
Before we go into the details of my discovery. Let’s see how this function normally used.
Example Usage of toHaveBeenCalled()
In the code below, funcB()
is calling funcA()
. When we write a unit test for funcB()
, we would need to ensure funcA is called as well.
Here is the example of the unit test. In the unit test below. We’re using toHaveBeenCalled()
to ensure funcA()
was executed when we're calling funcB()
.