title: Testing synchronous code
body: <p>I have a section of code that is using <a href="https://github.com/ybogdanov/node-sync" rel="nofollow">node-sync</a> like so:</p>
  
  <pre><code>function funcA() {
    return new Promise(function(resolve, reject) {
      Sync(function () {
        return funcB.sync();
      }, function (err, result) {
        if(err) {
          reject(err);
        } else {
          resolve(result);
        }
      });
  }
  </code></pre>
  
  <p>This code is tested using mocha+chai:</p>
  
  <pre><code>it("should return array", function() {
    return funcA().then(function(result) {
      expect(result).to.be.an.instanceof(Array);
    });
  });
  </code></pre>
  
  <p>It worked just fine couple of months ago, but now this test always times out:</p>
  
  <blockquote>
    <p>Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.</p>
  </blockquote>
  
  <p>What I've tried so far:</p>
  
  <ul>
  <li>using <code>done()</code> instead of returning a promise</li>
  <li>replacing <code>node-sync</code> with <code>synchronize.js</code></li>
  <li>increasing timeout</li>
  </ul>
  
  <p>What I found out, is that <code>expect(...</code> part of this test is, in fact, being called, but only after mocha kills the test. No matter what timeout interval is currently set, <code>expect(..</code> is being called always ~20 milliseconds after I get <code>Error: timeout</code> message.</p>
  
  <p>I fixed the issue by adding <code>setInterval(function(){}, 10)</code> on the top of the test file. <strong>I'd like to know why this worked and if there is some better way to fix that?</strong></p>
  
  <p>[EDIT] It looks like this is a node-version specific issue. Test fails on 0.12.4 but runs correctly on 0.10.38 .</p>
  
  <p>[EDIT] Actual code is available <a href="https://github.com/kdzwinel/Proofreader" rel="nofollow">here</a>.</p>