title: How to test a function that return void with Jest? Tyepscript
body: <p>I have some function and a type in file <code>retry.ts</code></p>
  <pre><code>export const retryNTimes =  (retryFunction: Function) =&gt; {
      let retry = 0;
      while(retry &lt; MAX_NUMBER_OF_RETRIES){
          try {
              retryFunction()
              break
          } catch (err) {
              console.log(`Try ${retry}: ${err}`)
              retry += 1
          }
      }
  } 
  
  type User = {
    userId: string
  }
  
  const TestUser = async ({
    userId,
  }:User) =&gt; {
    console.log(`userid : ${userId} `)
  }
  </code></pre>
  <p>I want to test test to make sure the function <code>retryNTimes</code> works.Then test to make sure it calls a function up to 3 times upon its failure. So I created a little TestUser function to do this with.</p>
  <p>In file <code>retry.test.ts</code>,</p>
  <pre><code>describe('retry Function',() =&gt; {
  
  test('retryNTimes function was call', () =&gt; {
      retryNTimes(function(){ TestUser()})
      expect(retryNTimes).toHaveBeenCalledTimes(1)
  })
  
  test('retry function to try 1 time', () =&gt; {
      retryNTimes(function(){ TestUser()})
      expect(TestUser).toHaveBeenCalledTimes(1)
  })
  
   test('retry function to try 2 times', () =&gt; {
       retryNTimes(function(){ TestUser()})
       expect(TestUser).toHaveBeenCalledTimes(2)
   })
  
   test('retry function to try 3 times', () =&gt; {
       retryNTimes(function(){ TestUser()})
       expect(TestUser).toHaveBeenCalledTimes(3)
   })
  
  })
  </code></pre>
  <p>However I recieve this error for the first 2 tests.</p>
  <pre><code>Matcher error: received value must be a mock or spy function
  
      Received has type:  function
      Received has value: [Function anonymous]
  
         9 | test('retryNTimes function was call', () =&gt; {
        10 |     retryNTimes(function(){ TestUser()})
      &gt; 11 |     expect(retryNTimes).toHaveBeenCalledTimes(1)
           |                         ^
        12 | })
  </code></pre>
  <p>And I know the second two wont work with this set up because Im pretty sure I need to mock the function catching an error before it calls it again.</p>
  <p>Ive been pretty bad with jest so far, so any help with setting up these tests is greatly appreciated.</p>