Espruino/tests/test_promise_exception.js
Gordon Williams abc94f59a5 Correct the handling of exceptions in promises
Ensure that exceptions have a 'stack' attribute if they can have children
2016-11-08 12:30:42 +00:00

35 lines
669 B
JavaScript

var test1, test2;
var p = new Promise(function(res,rej) {
throw "Bummer 1";
}).then(function(r) {
console.log("then");
}).catch(function(e) {
console.log("catch ",e);
test1 = 1;
});
process.on('uncaughtException', function(e) {
console.log("expected ",e);
if (e.toString().indexOf("Unhandled promise rejection")>=0)
test2 = 1;
});
var p = new Promise(function(res,rej) {
throw "Bummer 2";
}).then(function(r) {
console.log("then");
}).then(function(r) {
console.log("then");
}).then(function(r) {
console.log("then");
}).then(function(r) {
console.log("then");
});
setTimeout(function() {
result = test1 && test2;
}, 10);