Limit semantics under test

Because these tests concern the behavior of the PromiseReactionJob
abstract operation itself, they should avoid assumptions about the
correct implementation of that operation. Specifically: they should not
rely on the behavior of abupt completions returned from "reaction
handler" functions.

Re-implement tests to express control flow expectations using the
`$DONE` function only.
This commit is contained in:
Mike Pennisi 2015-12-28 17:14:32 -05:00
parent 5a8d1fdf77
commit 5f2ba2522f
6 changed files with 47 additions and 19 deletions

View File

@ -16,9 +16,16 @@ var expectedThis = fnGlobalObject(),
var p = Promise.resolve(obj).then(function(arg) { var p = Promise.resolve(obj).then(function(arg) {
if (this !== expectedThis) { if (this !== expectedThis) {
$ERROR("'this' must be global object, got " + this); $DONE("'this' must be global object, got " + this);
return;
} }
if (arg !== obj) { if (arg !== obj) {
$ERROR("Expected promise to be fulfilled by obj, actually " + arg); $DONE("Expected promise to be fulfilled by obj, actually " + arg);
return;
} }
}).then($DONE, $DONE);
$DONE();
}, function() {
$DONE('The promise should not be rejected.');
});

View File

@ -15,9 +15,16 @@ var expectedThis = undefined,
var p = Promise.resolve(obj).then(function(arg) { var p = Promise.resolve(obj).then(function(arg) {
if (this !== expectedThis) { if (this !== expectedThis) {
$ERROR("'this' must be undefined, got " + this); $DONE("'this' must be undefined, got " + this);
return;
} }
if (arg !== obj) { if (arg !== obj) {
$ERROR("Expected promise to be fulfilled by obj, actually " + arg); $DONE("Expected promise to be fulfilled by obj, actually " + arg);
return;
} }
}).then($DONE, $DONE);
$DONE();
}, function() {
$DONE('The promise should not be rejected.');
});

View File

@ -14,6 +14,10 @@ var obj = {};
var p = Promise.resolve(obj).then(/*Identity, Thrower*/) var p = Promise.resolve(obj).then(/*Identity, Thrower*/)
.then(function (arg) { .then(function (arg) {
if (arg !== obj) { if (arg !== obj) {
$ERROR("Expected promise to be fulfilled with obj, actually " + arg); $DONE("Expected promise to be fulfilled with obj, actually " + arg);
return;
} }
}).then($DONE, $DONE); $DONE();
}, function() {
$DONE('The promise should not be rejected.');
});

View File

@ -17,13 +17,17 @@ var expectedThis = fnGlobalObject(),
obj = {}; obj = {};
var p = Promise.reject(obj).then(function () { var p = Promise.reject(obj).then(function () {
$ERROR("Unexpected fulfillment; expected rejection."); $DONE("Unexpected fulfillment; expected rejection.");
}, function(arg) { }, function(arg) {
if (this !== expectedThis) { if (this !== expectedThis) {
$ERROR("'this' must be global object, got " + this); $DONE("'this' must be global object, got " + this);
return;
} }
if (arg !== obj) { if (arg !== obj) {
$ERROR("Expected promise to be rejected with obj, actually " + arg); $DONE("Expected promise to be rejected with obj, actually " + arg);
return;
} }
}).then($DONE, $DONE);
$DONE();
});

View File

@ -16,13 +16,17 @@ var expectedThis = undefined,
obj = {}; obj = {};
var p = Promise.reject(obj).then(function () { var p = Promise.reject(obj).then(function () {
$ERROR("Unexpected fulfillment; expected rejection."); $DONE("Unexpected fulfillment; expected rejection.");
}, function(arg) { }, function(arg) {
if (this !== expectedThis) { if (this !== expectedThis) {
$ERROR("'this' must be undefined, got " + this); $DONE("'this' must be undefined, got " + this);
return;
} }
if (arg !== obj) { if (arg !== obj) {
$ERROR("Expected promise to be rejected with obj, actually " + arg); $DONE("Expected promise to be rejected with obj, actually " + arg);
return;
} }
}).then($DONE, $DONE);
$DONE();
});

View File

@ -13,9 +13,11 @@ var obj = {};
var p = Promise.reject(obj).then(/*Identity, Thrower*/) var p = Promise.reject(obj).then(/*Identity, Thrower*/)
.then(function () { .then(function () {
$ERROR("Unexpected fulfillment - promise should reject."); $DONE("Unexpected fulfillment - promise should reject.");
}, function (arg) { }, function (arg) {
if (arg !== obj) { if (arg !== obj) {
$ERROR("Expected reject reason to be obj, actually " + arg); $DONE("Expected reject reason to be obj, actually " + arg);
return;
} }
}).then($DONE, $DONE); $DONE();
});