Skip to content

Commit

Permalink
Add extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuanjl committed Feb 11, 2018
1 parent 2884c00 commit b3f2360
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/es6/ES6Promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,23 @@ var tests = [
assert.isTrue(descriptor.configurable, "Promise.prototype.catch.configurable === true");
assert.areEqual('function', typeof descriptor.value, "typeof Promise.prototype.catch === 'function'");
assert.areEqual(1, Promise.prototype.catch.length, "Promise.prototype.catch.length === 1");
assert.areEqual("catch", Promise.prototype.catch.name, "Promise.prototype.catch.name === 'catch'");

var descriptor = Object.getOwnPropertyDescriptor(Promise.prototype, 'then');
assert.isTrue(descriptor.writable, "Promise.prototype.then.writable === true");
assert.isFalse(descriptor.enumerable, "Promise.prototype.then.enumerable === false");
assert.isTrue(descriptor.configurable, "Promise.prototype.then.configurable === true");
assert.areEqual('function', typeof descriptor.value, "typeof Promise.prototype.then === 'function'");
assert.areEqual(2, Promise.prototype.then.length, "Promise.prototype.then.length === 2");
assert.areEqual("then", Promise.prototype.then.name, "Promise.prototype.then.name === 'then'");

var descriptor = Object.getOwnPropertyDescriptor(Promise.prototype, 'finally');
assert.isTrue(descriptor.writable, "Promise.prototype.finally.writable === true");
assert.isFalse(descriptor.enumerable, "Promise.prototype.finally.enumerable === false");
assert.isTrue(descriptor.configurable, "Promise.prototype.finally.configurable === true");
assert.areEqual('function', typeof descriptor.value, "typeof Promise.prototype.finally === 'function'");
assert.areEqual(1, Promise.prototype.finally.length, "Promise.prototype.finally.length === 1");
assert.areEqual("finally", Promise.prototype.finally.name, "Promise.prototype.finally.name === 'finally'");

var descriptor = Object.getOwnPropertyDescriptor(Promise.prototype, Symbol.toStringTag);
assert.isFalse(descriptor.writable, "Promise.prototype[@@toStringTag].writable === false");
Expand Down Expand Up @@ -411,6 +414,26 @@ var tests = [
assert.isTrue(calledThen, "Promise.prototype.finally uses the modified then function");
}
},
{
name: "Promise.prototype.finally creates anonymous ThenFinally function",
body: function (index) {
class TestPromise extends Promise {
then (a, b)
{
this.first = a;
this.second = b;
this.argCount = arguments.length;
}
}
var p = new TestPromise(function() {});
p.finally(function() {});
assert.areEqual(p.first.name, "", "Promise.prototype.finally creates anonymous resolve handler");
assert.areEqual(p.first.length, 1, "Promise.prototype.finally creates resolve handler with length 1");
assert.areEqual(p.second.name, "", "Promise.prototype.finally creates anonymous reject handler");
assert.areEqual(p.second.length, 1, "Promise.prototype.finally creates reject handler with length 1");
assert.areEqual(p.argCount, 2, "Promise.prototype.finally invokes then with exactly 2 arguments");
}
},
{
name: "Subclass of Promise should return instances of the subclass from Promise methods",
body: function () {
Expand Down

0 comments on commit b3f2360

Please sign in to comment.