title: Argument of type 'Promise<unknown>' is not assignable to parameter of type 'void'.ts(2345) - mockReturnValueOnce
body: <p>The method <strong>mockReturnValueOnce</strong> is showing <strong>Argument of type 'Promise' is not assignable to parameter of type 'void'.ts(2345)</strong>.</p>
  <p>I already tried like this:</p>
  <pre class="lang-js prettyprint-override"><code> .spyOn(bcrypt, 'hash')
   .mockImplementation(async () =&gt; Promise.reject(new Error()))
  </code></pre>
  <p>looking this <a href="https://stackoverflow.com/questions/68490170/type-error-mockreturnvalueonce-from-jest-spyon-inferring-argument-type-as-voi">Type error: mockReturnValueOnce from jest.spyOn() inferring argument type as void</a> similar question, but has no effect.</p>
  <p>I noticed that vscode is inferring void for some reason in the method parameter, but I still haven't figured out why</p>
  <p>The signature of method:
  <a href="https://i.stack.imgur.com/6dvMY.png" rel="nofollow noreferrer">https://i.stack.imgur.com/6dvMY.png</a></p>
  <p>It's weird because I already mocked another class in another file and it worked:</p>
  <pre class="lang-js prettyprint-override"><code>jest.spyOn(encrypterStub, 'encrypt').mockReturnValueOnce(new Promise((resolve, reject) =&gt; reject(new Error())))
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>jest.mock('bcrypt', () =&gt; ({
    async hash (): Promise&lt;string&gt; {
      return new Promise((resolve) =&gt; resolve('hash'))
    }
  }))
  
  const salt = 12
  
  const makeSut = (): BcryptAdapter =&gt; {
    return new BcryptAdapter(salt)
  }
  
  describe('Bcrypt Adapter', () =&gt; {
    test('Should call bcrypt with correct values', async () =&gt; {
      const sut = makeSut()
      const hashSpy = jest.spyOn(bcrypt, 'hash')
      await sut.encrypt('any_value')
      expect(hashSpy).toHaveBeenCalledWith('any_value', salt)
    })
  
    test('Should return a hash on sucess', async () =&gt; {
      const sut = makeSut()
  
      const hash = await sut.encrypt('any_value')
      expect(hash).toBe('hash')
    })
  
    test('Should throw if bcrypt throws', async () =&gt; {
      const sut = makeSut()
      jest
        .spyOn(bcrypt, 'hash')
        .mockReturnValueOnce(
          // here
          new Promise((resolve, reject) =&gt; reject(new Error()))
        )
  
      const promise = await sut.encrypt('any_value')
      await expect(promise).rejects.toThrow()
    })
  })
  
  
  </code></pre>