Commit a539e705 authored by Daniel Shumway's avatar Daniel Shumway

fix, test: catch exceptions from recursively called functions

- fixes issue #9
parent 098f3b2e
Pipeline #5155577 passed with stage
in 57 seconds
......@@ -101,6 +101,7 @@ var Group = (function () {
_that.promise = _that.promise.then(function () {
_that.status = STATUS.PASSED;
}, function (error) {
if (_that.status !== STATUS.SKIPPED) {
_that.status = STATUS.FAILED;
_that.error = error;
......@@ -148,7 +149,8 @@ var Group = (function () {
clearTimeout(timeout);
//For the API to be completely, 100% consistent, allow recursion.
_that.promisify(resolution, group).then(res, rej);
}, rej);
}, rej)
.catch(rej); //Catch runtime exceptions during recursive `promisify`
});
}
......
......@@ -87,7 +87,7 @@ tape('Recursively resolving "weird" results', function (t) {
}
if (test.label === 'B') {
t.equal(test.status, Distilled.STATUS.FAILED, 'nested (mixed) promises/functions eventually pass correctly');
t.equal(test.status, Distilled.STATUS.FAILED, 'nested (mixed) promises/functions eventually fail correctly');
}
});
......@@ -107,3 +107,19 @@ tape('Recursively resolving "weird" results', function (t) {
});
});
});
tape('Exceptions from functions within promises (#9)', function (t) {
t.plan(1);
var suite = new Distilled(function (test) {
if (test.label === 'A') {
t.equal(test.status, Distilled.STATUS.FAILED, 'Exceptions from recursively called functions are caught correctly');
}
});
suite.test('A', function () {
return Promise.resolve(function () {
throw 'error';
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment