summaryrefslogtreecommitdiff
path: root/test/parallel/test-promises-unhandled-rejections.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/parallel/test-promises-unhandled-rejections.js')
-rw-r--r--test/parallel/test-promises-unhandled-rejections.js168
1 files changed, 90 insertions, 78 deletions
diff --git a/test/parallel/test-promises-unhandled-rejections.js b/test/parallel/test-promises-unhandled-rejections.js
index 5e7739daa5..8345096445 100644
--- a/test/parallel/test-promises-unhandled-rejections.js
+++ b/test/parallel/test-promises-unhandled-rejections.js
@@ -234,23 +234,27 @@ asyncTest('When re-throwing new errors in a promise catch, only the re-thrown' +
var promise2;
});
-asyncTest('unhandledRejection should not be triggered if a promise catch is' +
- ' attached synchronously upon the promise\'s creation',
- function(done) {
- var e = new Error();
- onUnhandledFail(done);
- Promise.reject(e).then(common.fail, function() {});
-});
-
-asyncTest('unhandledRejection should not be triggered if a promise catch is' +
- ' attached synchronously upon the promise\'s creation',
- function(done) {
- var e = new Error();
- onUnhandledFail(done);
- new Promise(function(_, reject) {
- reject(e);
- }).then(common.fail, function() {});
-});
+asyncTest(
+ 'unhandledRejection should not be triggered if a promise catch is' +
+ ' attached synchronously upon the promise\'s creation',
+ function(done) {
+ var e = new Error();
+ onUnhandledFail(done);
+ Promise.reject(e).then(common.fail, function() {});
+ }
+);
+
+asyncTest(
+ 'unhandledRejection should not be triggered if a promise catch is' +
+ ' attached synchronously upon the promise\'s creation',
+ function(done) {
+ var e = new Error();
+ onUnhandledFail(done);
+ new Promise(function(_, reject) {
+ reject(e);
+ }).then(common.fail, function() {});
+ }
+);
asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' +
' prevent unhandledRejection', function(done) {
@@ -360,19 +364,21 @@ asyncTest('A rejected promise derived from throwing in a fulfillment handler' +
});
});
-asyncTest('A rejected promise derived from returning a synchronously-rejected' +
- ' promise in a fulfillment handler does trigger unhandledRejection',
- function(done) {
- var e = new Error();
- var _promise;
- onUnhandledSucceed(done, function(reason, promise) {
- assert.strictEqual(e, reason);
- assert.strictEqual(_promise, promise);
- });
- _promise = Promise.resolve().then(function() {
- return Promise.reject(e);
- });
-});
+asyncTest(
+ 'A rejected promise derived from returning a synchronously-rejected' +
+ ' promise in a fulfillment handler does trigger unhandledRejection',
+ function(done) {
+ var e = new Error();
+ var _promise;
+ onUnhandledSucceed(done, function(reason, promise) {
+ assert.strictEqual(e, reason);
+ assert.strictEqual(_promise, promise);
+ });
+ _promise = Promise.resolve().then(function() {
+ return Promise.reject(e);
+ });
+ }
+);
// Combinations with Promise.all
asyncTest('Catching the Promise.all() of a collection that includes a' +
@@ -382,21 +388,23 @@ asyncTest('Catching the Promise.all() of a collection that includes a' +
Promise.all([Promise.reject(e)]).then(common.fail, function() {});
});
-asyncTest('Catching the Promise.all() of a collection that includes a ' +
- 'nextTick-async rejected promise prevents unhandledRejection',
- function(done) {
- var e = new Error();
- onUnhandledFail(done);
- var p = new Promise(function(_, reject) {
+asyncTest(
+ 'Catching the Promise.all() of a collection that includes a ' +
+ 'nextTick-async rejected promise prevents unhandledRejection',
+ function(done) {
+ var e = new Error();
+ onUnhandledFail(done);
+ var p = new Promise(function(_, reject) {
+ process.nextTick(function() {
+ reject(e);
+ });
+ });
+ p = Promise.all([p]);
process.nextTick(function() {
- reject(e);
+ p.then(common.fail, function() {});
});
- });
- p = Promise.all([p]);
- process.nextTick(function() {
- p.then(common.fail, function() {});
- });
-});
+ }
+);
asyncTest('Failing to catch the Promise.all() of a collection that includes' +
' a rejected promise triggers unhandledRejection for the returned' +
@@ -513,26 +521,28 @@ asyncTest('Waiting for some combination of promise microtasks + ' +
});
});
-asyncTest('Waiting for some combination of promise microtasks +' +
- ' process.nextTick to attach a catch handler is still soon enough' +
- ' to prevent unhandledRejection: inside setImmediate',
- function(done) {
- var e = new Error();
- onUnhandledFail(done);
+asyncTest(
+ 'Waiting for some combination of promise microtasks +' +
+ ' process.nextTick to attach a catch handler is still soon enough' +
+ ' to prevent unhandledRejection: inside setImmediate',
+ function(done) {
+ var e = new Error();
+ onUnhandledFail(done);
- setImmediate(function() {
- var a = Promise.reject(e);
- Promise.resolve().then(function() {
- process.nextTick(function() {
- Promise.resolve().then(function() {
- process.nextTick(function() {
- a.catch(function() {});
+ setImmediate(function() {
+ var a = Promise.reject(e);
+ Promise.resolve().then(function() {
+ process.nextTick(function() {
+ Promise.resolve().then(function() {
+ process.nextTick(function() {
+ a.catch(function() {});
+ });
});
});
});
});
- });
-});
+ }
+);
asyncTest('Waiting for some combination of promise microtasks +' +
' process.nextTick to attach a catch handler is still soon enough' +
@@ -612,28 +622,30 @@ asyncTest('setImmediate + promise microtasks is too late to attach a catch' +
});
});
-asyncTest('Promise unhandledRejection handler does not interfere with domain' +
- ' error handlers being given exceptions thrown from nextTick.',
- function(done) {
- var d = domain.create();
- var domainReceivedError;
- d.on('error', function(e) {
- domainReceivedError = e;
- });
- d.run(function() {
- var e = new Error('error');
- var domainError = new Error('domain error');
- onUnhandledSucceed(done, function(reason, promise) {
- assert.strictEqual(reason, e);
- assert.strictEqual(domainReceivedError, domainError);
- d.dispose();
+asyncTest(
+ 'Promise unhandledRejection handler does not interfere with domain' +
+ ' error handlers being given exceptions thrown from nextTick.',
+ function(done) {
+ var d = domain.create();
+ var domainReceivedError;
+ d.on('error', function(e) {
+ domainReceivedError = e;
});
- Promise.reject(e);
- process.nextTick(function() {
- throw domainError;
+ d.run(function() {
+ var e = new Error('error');
+ var domainError = new Error('domain error');
+ onUnhandledSucceed(done, function(reason, promise) {
+ assert.strictEqual(reason, e);
+ assert.strictEqual(domainReceivedError, domainError);
+ d.dispose();
+ });
+ Promise.reject(e);
+ process.nextTick(function() {
+ throw domainError;
+ });
});
- });
-});
+ }
+);
asyncTest('nextTick is immediately scheduled when called inside an event' +
' handler', function(done) {