title: How to set timeout in a javascript unit test using sinon.useFakeTimers
body: <p>I'm trying to test the following method:</p>
  <pre><code>endSocketConn(socket) {
      if(!socket) {
          return;
      }
  
      socket.setTimeout(5000, () =&gt; {
          socket.destroy();
      });
  
      socket.end('commandToSend');
  }
  </code></pre>
  <p>The scenario I need to test is the one where if more than 5seconds are elapsed then socket.destroy() must be called one time</p>
  <pre><code>describe('Testing API | socketPool methods', async function () {
  
      beforeEach(async function () {
          let clock = sinon.useFakeTimers();
          let socketMock = {
              setTimeout: sinon.spy(),
              destroy: sinon.spy(),
              end: sinon.spy(), 
          };
      });
  
      afterEach(async function () {
          clock &amp;&amp; clock.restore();
      });
      
      describe('Testing endSocketConn() function', function () {
          
          it('It should execute socket.destroy if timeout occurred after sending commandToSend', async function () {
              let result;
              let error = false;
              try {
                  clock.tick(6000);
                  result = await file.endSocketConn(socketMock);
              } catch (err) {
                  error = err;
              }
              expect(error).to.be.false;
              sinon.assert.callCount(socketMock.setTimeout, 1);
              sinon.assert.callCount(socketMock.end, 1);
              
              sinon.assert.callCount(socketMock.destroy, 1); 
              // AssertError: expected spy to be called once but was called 0 times
          });
      });
  </code></pre>
  <p>Any idea why the timeout is not being properly simulated?</p>