title: How do I resolve the outer promise inside a mocked function with Jest?
body: <p>Here is my basic setup I'm trying to test.</p>
  
  <p>First, Method I'm testing: </p>
  
  <pre><code>Thing.prototype.getStuff = function(){
     return new Promise((resolve, reject) =&gt; {
       // Bunch of business logic...
       this.getOtherStuff().then((data) =&gt; {
          // Perform business logic with data. I want to test that certain things get called depending on the response. 
  
           mockedThirdParty._performLogic().nestedLogic(null, () =&gt; {
             // Now resolve outer promise here with new data
             resolve({newdata: goodstuff});
             // Or depending on the logic, reject
          });
       });
     });
  }
  </code></pre>
  
  <p>In my test for <code>getStuff</code>, I am mocking the response for <code>getOtherStuff</code>. I'm doing that like so:</p>
  
  <pre><code>Thing.prototype.getOtherStuff.mockImplementationOnce(()=&gt; Promise.resolve({data: 'value'}));
  </code></pre>
  
  <p>So my whole test looks like this: </p>
  
  <pre><code>test('Here is my test name', async () =&gt; {
  Thing.prototype.getOtherStuff.mockImplementationOnce(()=&gt; Promise.resolve({data: 'value'}));
  
  let instance = new Thing();
  
  await instance.getStuff();
  
  // We never get to this test because the test timeouts
  expect(Thing.prototype._performLogic).toHaveBeenCalled()
  });
  </code></pre>
  
  <p>So my test always timeout because I'm never resolving the outer promise in <code>getStuff</code>. I get this error: </p>
  
  <blockquote>
    <p>Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error:</p>
  </blockquote>
  
  <p>How can I resolve this outer Promise while also mocking the inner async call <code>getOtherStuff</code>? </p>
  
  <p><strong>EDIT</strong> -> See function above</p>
  
  <p>How do I pass a callback to a mocked implementation of a third-party library? </p>
  
  <p>I'm trying it like this, but I don't think I defining <code>nestedLogic</code> correctly: </p>
  
  <pre><code>
     const mockedScene = {
        nestedLogic: jest.fn().mockImplementation(() =&gt; Promise.resolve())
     }
  
     jest
     .spyOn(Thirdparty.prototype, "_performLogic")
     .mockImplementation(() =&gt; (mockedScene))
  
  </code></pre>