title: Jest unit test for a debounce function
body: <p>I am trying to write a unit test for a <em>debounce</em> function. I'm having a hard time thinking about it.</p>
  <p>This is the code:</p>
  <pre class="lang-js prettyprint-override"><code>function debouncer(func, wait, immediate) {
    let timeout;
  
    return (...args) =&gt; {
      clearTimeout(timeout);
  
      timeout = setTimeout(() =&gt; {
        timeout = null;
        if (!immediate) 
          func.apply(this, args);
      }, wait);
  
      if (immediate &amp;&amp; !timeout) 
        func.apply(this, args);
    };
  }
  </code></pre>
  <p>How should I start?</p>