-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test implementation of done() from promises-aplus/unhandled-rejection…
- Loading branch information
Showing
8 changed files
with
169 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const adapter = require('../../test/pinky-adapter'); | ||
|
||
// Create a rejected promise | ||
var promise = adapter.rejected(new Error('Crash!')); | ||
|
||
/* | ||
A crash should occur: | ||
There are no onRejected handlers to handle the rejection. | ||
*/ | ||
|
||
promise.done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const adapter = require('../../test/pinky-adapter'); | ||
|
||
// Create a pending promise | ||
var promise = adapter.pending(); | ||
|
||
/* | ||
A crash should occur: | ||
There are no onRejected handlers to handle the rejection. | ||
*/ | ||
|
||
promise.done(); | ||
|
||
promise.reject(new Error('Crash!')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const adapter = require('../../test/pinky-adapter'); | ||
|
||
// Create a rejected promise | ||
var promise = adapter.rejected(new Error('Crash!')); | ||
|
||
/* | ||
A crash should occur: | ||
There are no onRejected handlers to handle the rejection. | ||
*/ | ||
|
||
promise | ||
.then( | ||
function(value) { | ||
console.log('Fulfilled 1: '+value); | ||
}, | ||
null | ||
) | ||
.done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const adapter = require('../../test/pinky-adapter'); | ||
|
||
// Create a rejected promise | ||
var promise = adapter.rejected(new Error('Crash!')); | ||
|
||
/* | ||
A crash should occur: | ||
Since the first onRejected handler throws, and there are no other onRejected handlers | ||
*/ | ||
|
||
promise | ||
.then( | ||
function(value) { | ||
console.log('Fulfilled 1: '+value); | ||
}, | ||
function(reason) { | ||
console.log('Rejected 1: '+reason); | ||
throw reason; // Throw again to reject the next promise | ||
} | ||
) | ||
.done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const adapter = require('../../test/pinky-adapter'); | ||
|
||
// Create a rejected promise | ||
var promise = adapter.rejected(new Error('Crash!')); | ||
|
||
/* | ||
A crash should occur: | ||
Since the first onRejected handler throws, the next onRejected handler throws, and there are no other onRejected handlers to handle the rejection | ||
*/ | ||
|
||
promise | ||
.then( | ||
function(value) { | ||
console.log('Fulfilled 1: '+value); | ||
}, | ||
function(reason) { | ||
console.log('Rejected 1: '+reason); | ||
throw reason; // Throw again to reject the next promise | ||
} | ||
) | ||
.then( | ||
function(value) { | ||
console.log('Fulfilled 2: '+value); | ||
}, | ||
function(reason) { | ||
console.log('Rejected 2: '+reason); | ||
throw reason; // Causes a crash; no more onRejection handlers | ||
} | ||
) | ||
.done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const adapter = require('../../test/pinky-adapter'); | ||
|
||
// Create a fulfilled promise | ||
var promise = adapter.fulfilled('A value'); | ||
|
||
/* | ||
A crash should occur: | ||
There are no onRejected handlers to handle the rejection caused by throwing within the onFulfilled handler | ||
*/ | ||
|
||
promise | ||
.then( | ||
function(value) { | ||
console.log('Fulfilled with '+value); | ||
throw new Error('Crash!'); | ||
}, | ||
null | ||
) | ||
.done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters