mirror of https://github.com/tc39/test262.git
Assert that promise callbacks were actually called. Closes #1328
Originally reported here: https://github.com/tc39/test262/pull/1328, OP passed on revising.
This commit is contained in:
parent
02f1a0b630
commit
66df349af3
|
@ -6,41 +6,34 @@ description: finally observably calls .then
|
|||
esid: sec-promise.prototype.finally
|
||||
features: [Promise.prototype.finally]
|
||||
flags: [async]
|
||||
includes: [promiseHelper.js]
|
||||
---*/
|
||||
|
||||
var initialThenCount = 0;
|
||||
var sequence = [];
|
||||
var noReason = {};
|
||||
var no = Promise.reject(noReason);
|
||||
no.then = function () {
|
||||
initialThenCount += 1;
|
||||
sequence.push(1);
|
||||
return Promise.prototype.then.apply(this, arguments);
|
||||
};
|
||||
|
||||
var onFinallyThenCount = 0;
|
||||
var yesValue = {};
|
||||
var yes = Promise.resolve(yesValue);
|
||||
yes.then = function () {
|
||||
onFinallyThenCount += 1;
|
||||
sequence.push(4);
|
||||
return Promise.prototype.then.apply(this, arguments);
|
||||
};
|
||||
|
||||
var finallyCalled = false;
|
||||
var catchCalled = false;
|
||||
|
||||
no.catch(function (e) {
|
||||
sequence.push(2);
|
||||
assert.sameValue(e, noReason);
|
||||
throw e;
|
||||
}).finally(function () {
|
||||
finallyCalled = true;
|
||||
sequence.push(3);
|
||||
return yes;
|
||||
}).catch(function (e) {
|
||||
catchCalled = true;
|
||||
sequence.push(5);
|
||||
assert.sameValue(e, noReason);
|
||||
}).then(function () {
|
||||
assert.sameValue(finallyCalled, true, 'initial finally was called');
|
||||
assert.sameValue(initialThenCount, 1, 'initial finally invokes .then once');
|
||||
|
||||
assert.sameValue(catchCalled, true, 'catch was called');
|
||||
assert.sameValue(onFinallyThenCount, 1, 'onFinally return promise has .then invoked once');
|
||||
checkSequence(sequence, "All expected callbacks called in correct order");
|
||||
$DONE();
|
||||
}).catch($ERROR);
|
||||
|
|
|
@ -6,18 +6,24 @@ description: finally on a rejected promise can not convert to a fulfillment
|
|||
esid: sec-promise.prototype.finally
|
||||
features: [Promise.prototype.finally]
|
||||
flags: [async]
|
||||
includes: [promiseHelper.js]
|
||||
---*/
|
||||
|
||||
var sequence = [];
|
||||
var original = {};
|
||||
var replacement = {};
|
||||
|
||||
var p = Promise.reject(original);
|
||||
|
||||
p.finally(function () {
|
||||
p.finally(function() {
|
||||
sequence.push(1);
|
||||
assert.sameValue(arguments.length, 0, 'onFinally receives zero args');
|
||||
return replacement;
|
||||
}).then(function () {
|
||||
}).then(function() {
|
||||
$ERROR('promise is rejected pre-finally; onFulfill should not be called');
|
||||
}).catch(function (reason) {
|
||||
}).catch(function(reason) {
|
||||
sequence.push(2);
|
||||
assert.sameValue(reason, original, 'onFinally can not override the rejection value by returning');
|
||||
}).then($DONE).catch($ERROR);
|
||||
}).then(function() {
|
||||
checkSequence(sequence, "All expected callbacks called in correct order");
|
||||
$DONE();
|
||||
}).catch($ERROR);
|
||||
|
|
|
@ -6,18 +6,24 @@ description: finally on a rejected promise can override the rejection reason
|
|||
esid: sec-promise.prototype.finally
|
||||
features: [Promise.prototype.finally]
|
||||
flags: [async]
|
||||
includes: [promiseHelper.js]
|
||||
---*/
|
||||
|
||||
var sequence = [];
|
||||
var original = {};
|
||||
var thrown = {};
|
||||
|
||||
var p = Promise.reject(original);
|
||||
|
||||
p.finally(function () {
|
||||
sequence.push(1);
|
||||
assert.sameValue(arguments.length, 0, 'onFinally receives zero args');
|
||||
throw thrown;
|
||||
}).then(function () {
|
||||
$ERROR('promise is rejected; onFulfill should not be called');
|
||||
}).catch(function (reason) {
|
||||
sequence.push(2);
|
||||
assert.sameValue(reason, thrown, 'onFinally can override the rejection reason by throwing');
|
||||
}).then($DONE).catch($ERROR);
|
||||
}).then(function() {
|
||||
checkSequence(sequence, "All expected callbacks called in correct order");
|
||||
$DONE();
|
||||
}).catch($ERROR);
|
||||
|
|
|
@ -6,15 +6,20 @@ description: finally on a fulfilled promise can not override the resolution valu
|
|||
esid: sec-promise.prototype.finally
|
||||
features: [Promise.prototype.finally]
|
||||
flags: [async]
|
||||
includes: [promiseHelper.js]
|
||||
---*/
|
||||
|
||||
var sequence = [];
|
||||
var obj = {};
|
||||
|
||||
var p = Promise.resolve(obj);
|
||||
|
||||
p.finally(function () {
|
||||
sequence.push(1);
|
||||
assert.sameValue(arguments.length, 0, 'onFinally receives zero args');
|
||||
return {};
|
||||
}).then(function (x) {
|
||||
sequence.push(2);
|
||||
assert.sameValue(x, obj, 'onFinally can not override the resolution value');
|
||||
}).then($DONE).catch($ERROR);
|
||||
}).then(function() {
|
||||
checkSequence(sequence, "All expected callbacks called in correct order");
|
||||
$DONE();
|
||||
}).catch($ERROR);
|
||||
|
|
|
@ -6,41 +6,35 @@ description: finally observably calls .then
|
|||
esid: sec-promise.prototype.finally
|
||||
features: [Promise.prototype.finally]
|
||||
flags: [async]
|
||||
includes: [promiseHelper.js]
|
||||
---*/
|
||||
|
||||
var initialThenCount = 0;
|
||||
var sequence = [];
|
||||
var yesValue = {};
|
||||
var yes = Promise.resolve(yesValue);
|
||||
yes.then = function () {
|
||||
initialThenCount += 1;
|
||||
sequence.push(1);
|
||||
return Promise.prototype.then.apply(this, arguments);
|
||||
};
|
||||
|
||||
var onFinallyThenCount = 0;
|
||||
var noReason = {};
|
||||
var no = Promise.reject(noReason);
|
||||
no.then = function () {
|
||||
onFinallyThenCount += 1;
|
||||
sequence.push(4);
|
||||
return Promise.prototype.then.apply(this, arguments);
|
||||
};
|
||||
|
||||
var finallyCalled = false;
|
||||
var catchCalled = false;
|
||||
|
||||
yes.then(function (x) {
|
||||
sequence.push(2);
|
||||
assert.sameValue(x, yesValue);
|
||||
return x;
|
||||
}).finally(function () {
|
||||
finallyCalled = true;
|
||||
sequence.push(3);
|
||||
return no;
|
||||
}).catch(function (e) {
|
||||
catchCalled = true;
|
||||
sequence.push(5);
|
||||
assert.sameValue(e, noReason);
|
||||
}).then(function () {
|
||||
assert.sameValue(finallyCalled, true, 'initial finally was called');
|
||||
assert.sameValue(initialThenCount, 1, 'initial finally invokes .then once');
|
||||
|
||||
assert.sameValue(catchCalled, true, 'catch was called');
|
||||
assert.sameValue(onFinallyThenCount, 1, 'onFinally return promise has .then invoked once');
|
||||
checkSequence(sequence, "All expected callbacks called in correct order");
|
||||
$DONE();
|
||||
}).catch($ERROR);
|
||||
|
||||
|
|
Loading…
Reference in New Issue