title: expect(jest.fn()).toHaveBeenCalled() fails even though the function has been called
body: <p>I'm trying to unit test a function that returns a promise. I'm having challenges verifying if
  the mocked functions are called. Here's what I've done.,</p>
  <pre class="lang-js prettyprint-override"><code>// codetotest.js
  const { SomeModule, isSomething, isSomethingElse } = require(&quot;some-module&quot;);
  
  exports.somefunction = (param1, param2)=&gt; {
      const someModule = new SomeModule();
  
      someModule.someMethod(&quot;aaa&quot;, isSomething);
      someModule.someMethod(&quot;bbb&quot;, isSomethingElse);
  
      return (someModule.someOtherMethod(param1)
      .then(()=&gt;{someModule.run(param2)}));
  }
  </code></pre>
  <p>And this is the test file, the test says the mocked functions are not called, but I do see the console statement in the mock function is being displayed.</p>
  <pre class="lang-js prettyprint-override"><code>// codetotest.test.js
  const { somefunction} = require(&quot;./codetotest.js&quot;);
  const { SomeModule } = require(&quot;some-module&quot;);
  
  jest.mock(&quot;some-module&quot;, () =&gt; {
      return {
          SomeModule: jest.fn().mockImplementation(() =&gt; {
              return {
                  someMethod: jest.fn((param, fn) =&gt; { console.log(&quot;This prints!&quot;); }),
                  someOtherMethod: jest.fn((param) =&gt; { return Promise.resolve(() =&gt; { }) }),
                  run: jest.fn((param) =&gt; { return Promise.resolve(() =&gt; { return []; }) })
              }
          })
      };
  });
  
  afterEach(() =&gt; {
      jest.resetAllMocks();
      jest.restoreAllMocks();
  });
  
  describe(&quot;Test codetotest.js&quot;, () =&gt; {
      it(&quot;somefunction() - success&quot;, async () =&gt; {
          const someModule = new SomeModule();
  
          let output = await somefunction(&quot;param1&quot;, &quot;param2&quot;);
  
          expect(SomeModule).toHaveBeenCalled();
          expect(someModule.someMethod).toHaveBeenCalled(); // This fails
  
          await expect(someModule.someOtherMethod.mock.results[0]).resolves;
          expect(someModule.someOtherMethod).toHaveBeenCalled(); // This fails
  
          await expect(someModule.run.mocks.results[0]).resolves;
          expect(someModule.run).toHaveBeenCalled(); // This fails
      });
  });
  </code></pre>
  <p>Appreciate any help/pointers.</p>
  <p>Thank you.</p>
  <p>P.S: I'm still a beginner when it comes to nodeJs development and unit testing.</p>