Skip to content
Snippets Groups Projects
Commit 0caf4eec authored by Brian Terlson's avatar Brian Terlson
Browse files

Merge pull request #100 from smikes/promise-tests

add initial set of tests for Promise
parents 5c5dffce f5447735
No related branches found
No related tags found
No related merge requests found
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
PerformPromiseThen
Ref 25.4.5.3.1
author: Sam Mikes
description: Promise.prototype.then immediately queues handler if fulfilled
includes: [PromiseHelper.js]
---*/
var sequence = [],
pResolve,
p = new Promise(function (resolve, reject) {
pResolve = resolve;
});
sequence.push(1);
pResolve();
p.then(function () {
sequence.push(3);
checkSequence(sequence, "Should be first");
}).catch($DONE);
Promise.resolve().then(function () {
// enqueue another then-handler
p.then(function () {
sequence.push(5);
checkSequence(sequence, "Should be third");
}).then($DONE, $DONE);
sequence.push(4);
checkSequence(sequence, "Should be second");
}).catch($DONE);
sequence.push(2);
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
PerformPromiseThen
Ref 25.4.5.3.1
author: Sam Mikes
description: Promise.prototype.then immediately queues handler if rejected
includes: [PromiseHelper.js]
---*/
var sequence = [],
pReject,
p = new Promise(function (resolve, reject) {
pReject = reject;
});
sequence.push(1);
pReject();
p.then(function () {
$ERROR("Should not be called -- Promise rejected.");
}, function () {
sequence.push(3);
checkSequence(sequence, "Should be first");
}).catch($DONE);
Promise.resolve().then(function () {
// enqueue another then-handler
p.then(function () {
$ERROR("Should not be called (2) -- Promise rejected.");
}, function () {
sequence.push(5);
checkSequence(sequence, "Should be third");
}).then($DONE, $DONE);
sequence.push(4);
checkSequence(sequence, "Should be second");
}).catch($DONE);
sequence.push(2);
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise prototype object is an ordinary object
author: Sam Mikes
description: Promise prototype does not have [[PromiseState]] internal slot
negative: TypeError
---*/
Promise.call(Promise.prototype, function () {});
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise prototype object is an ordinary object
author: Sam Mikes
description: Promise prototype is a standard built-in Object
---*/
if (!(Promise.prototype instanceof Object)) {
$ERROR("Expected Promise.prototype to be an Object");
}
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Promise.prototype.constructor is the Promise constructor
author: Sam Mikes
description: Promise.prototype.constructor is the Promise constructor
---*/
if (Promise.prototype.constructor !== Promise) {
$ERROR("Expected Promise.prototype.constructor to be Promise");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment