title: Javascript Jest Unit Test Time Interval
body: <p>i need some help with the Unittest for my Time Intervals.
  Maybe someone can tell me how it works? I am new with writing Unit Test..
  An example would be great.</p>
  <p>Here is my Code i want to Test:</p>
  <pre><code>export const dayIntervalFromDate = (date) =&gt; {
    const fromDate = new Date(date);
    fromDate.setHours(0, 0, 0, 0);
  
    const toDate = new Date(date);
    toDate.setHours(23, 59, 59, 999);
    return { from: fromDate, to: toDate };
  }
  </code></pre>
  <p><strong>dayIntervalFromDate Test</strong></p>
  <pre><code>    it(&quot;returns day interval from date&quot;, () =&gt; {
          const mockDayInterval = new Date('2021-01-01');
          const expectedFrom = new Date('2021-01-01');
          expectedFrom.setHours(0, 0, 0, 0);
          const expectedTo = new Date('2021-01-01');
          expectedTo.setHours(23, 59, 59, 999);
  
          jest.fn(() =&gt; mockDayInterval);
        
          const { from , to } = dayIntervalFromDate(Date);
    
          expect(from).toEqual(expectedFrom);
          expect(to).toEqual(expectedTo);
      });
  </code></pre>
  <p><a href="https://i.stack.imgur.com/qwzj7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qwzj7.png" alt="failed" /></a></p>