title: Jest - How to mock nested function?
body: <p>I've got function provided by lib (project dependency from NPM). This function has a signature like </p>
  
  <pre><code>function dependency(
    someParam: string,
    callback: (data: string) =&gt; void
  ): void { ... }
  </code></pre>
  
  <p>This function has been called by my function (that I need to test) in the way like below:</p>
  
  <pre><code>async function tested(): Promise&lt;string&gt; {
    return new Promise&lt;string&gt;((resolve): void =&gt; dependency('qwerty', resolve));
  }
  </code></pre>
  
  <p>I need to test my <code>tested</code> function with Jest but I'd like to test it in the unit-test style, so I need to mock the result from <code>dependency</code>. This example is pretty simple, but in reality there are some additional logic that I need to give different data from <code>dependency</code>.</p>
  
  <p>Spying on this function informs me that it's being called, but I need to mock implementation and <strong>completely prevent executing of the lib's implementation</strong>.</p>