Based on your code , I assume that your funcB function works with the code synchronously .
So, when I create funcB this way:
function funcB() { return [1, 2, 3]; }
And run the test, Mocha shows an error:
Error: Exceeded 2000 ms. Verify that the done () callback is called in this test.
But if I convert funcB to an asynchronous function like this:
function funcB(cb) { process.nextTick(function () { cb(null, [1, 2, 3]); }); }
Mocha runs the test without problems:
β should return an array
So, my complete code that works fine (comment funcB is the one that will throw the error):
// install dependencies // npm install promise // npm install sync var Promise = require('promise'); var assert = require('assert'); var Sync = require('sync'); function funcA() { return new Promise(function (resolve, reject) { Sync(function () { return funcB.sync(); }, function (err, result) { if (err) { reject(err); } else { resolve(result); } }); }); } // function funcB() { // return [1, 2, 3]; // } function funcB(cb) { process.nextTick(function () { cb(null, [1, 2, 3]); }); } it("should return an array", function(done) { return funcA().then( function (result) { console.log(result); assert.equal(Array.isArray(result), true); done(); } ); });
So, I believe that the misuse of the synchronization method (using it on synchronous functions) created by the synchronization library is the one that causes this problem.