The core of the problem is that the code you have is essentially:
try { var versions = upgrade.getVersions(); } catch (err){ return done(err); } assert(versions && versions.length > 0, 'Should have at least one version.'); assert.equal(1, 2);
Looking at this, it should be clear that if these statements are thrown away, then the callback will not be executed.
try { var versions = upgrade.getVersions(); assert(versions && versions.length > 0, 'Should have at least one version.'); assert.equal(1, 2);
looks more like what you want:
upgrade.getVersions().then(function (versions) { assert(versions && versions.length > 0, 'Should have at least one version.'); assert.equal(1, 2); // this throws the exception which causes the test case not even exist }).then(done, done);
Node to have this execute statements and then move the callbacks to a secondary .then() , which will always handle errors.
However, it would be much easier to simply return the promise as
return upgrade.getVersions().then(function (versions) { assert(versions && versions.length > 0, 'Should have at least one version.'); assert.equal(1, 2);
so that Mocha controls the promise itself without a callback.
source share