mirror of https://github.com/tc39/test262.git
Promise.prototype.finally: add missing tests
Per: - https://github.com/tc39/test262/issues/866#issuecomment-328565337 - https://github.com/tc39/test262/issues/866#issuecomment-359978873 Closes #866.
This commit is contained in:
parent
8b71c5fea5
commit
7c5b5bf750
|
@ -2,7 +2,7 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
author: Sathya Gunasekaran
|
||||
description: finally calls the SpeciesConstructor
|
||||
description: finally calls the SpeciesConstructor and creates the right amount of promises
|
||||
esid: sec-promise.prototype.finally
|
||||
features: [Promise.prototype.finally]
|
||||
flags: [async]
|
||||
|
@ -22,4 +22,4 @@ new FooPromise(r => r())
|
|||
.then(() => {
|
||||
assert.sameValue(count, 6, "6 new promises were created");
|
||||
$DONE();
|
||||
});
|
||||
}, $ERROR);
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2018 Jordan Harband. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
author: Jordan Harband
|
||||
description: Promise subclass finally on rejected creates the proper number of subclassed promises
|
||||
esid: sec-promise.prototype.finally
|
||||
features: [Promise.prototype.finally]
|
||||
flags: [async]
|
||||
---*/
|
||||
|
||||
var count = 0;
|
||||
class FooPromise extends Promise {
|
||||
constructor(resolve, reject) {
|
||||
count++;
|
||||
return super(resolve, reject);
|
||||
}
|
||||
}
|
||||
|
||||
FooPromise.reject().finally(() => {}).then($ERROR).catch(() => {
|
||||
assert.sameValue(7, count);
|
||||
$DONE();
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2018 Jordan Harband. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
author: Jordan Harband
|
||||
description: Promise subclass finally on resolved creates the proper number of subclassed promises
|
||||
esid: sec-promise.prototype.finally
|
||||
features: [Promise.prototype.finally]
|
||||
flags: [async]
|
||||
---*/
|
||||
|
||||
var count = 0;
|
||||
class FooPromise extends Promise {
|
||||
constructor(resolve, reject) {
|
||||
count++;
|
||||
return super(resolve, reject);
|
||||
}
|
||||
}
|
||||
|
||||
FooPromise.resolve().finally(() => {}).then(() => {
|
||||
assert.sameValue(6, count);
|
||||
$DONE();
|
||||
}, $ERROR);
|
17
test/built-ins/Promise/prototype/finally/subclass-species-constructor-reject-count.js
vendored
Normal file
17
test/built-ins/Promise/prototype/finally/subclass-species-constructor-reject-count.js
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright (C) 2018 Jordan Harband. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
author: Jordan Harband
|
||||
description: finally on rejected Promise calls the SpeciesConstructor
|
||||
esid: sec-promise.prototype.finally
|
||||
features: [Promise.prototype.finally]
|
||||
---*/
|
||||
|
||||
class FooPromise extends Promise {
|
||||
static get [Symbol.species]() { return Promise; }
|
||||
}
|
||||
|
||||
var p = Promise.reject().finally(() => FooPromise.reject());
|
||||
|
||||
assert.sameValue(p instanceof Promise, true);
|
||||
assert.sameValue(p instanceof FooPromise, false);
|
18
test/built-ins/Promise/prototype/finally/subclass-species-constructor-resolve-count.js
vendored
Normal file
18
test/built-ins/Promise/prototype/finally/subclass-species-constructor-resolve-count.js
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2018 Jordan Harband. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
author: Jordan Harband
|
||||
description: finally on resolved Promise calls the SpeciesConstructor
|
||||
esid: sec-promise.prototype.finally
|
||||
features: [Promise.prototype.finally]
|
||||
flags: [async]
|
||||
---*/
|
||||
|
||||
class FooPromise extends Promise {
|
||||
static get [Symbol.species]() { return Promise; }
|
||||
}
|
||||
|
||||
var p = Promise.resolve().finally(() => FooPromise.resolve());
|
||||
|
||||
assert.sameValue(p instanceof Promise, true);
|
||||
assert.sameValue(p instanceof FooPromise, false);
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (C) 2018 Jordan Harband. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
author: Jordan Harband
|
||||
description: >
|
||||
Promise.prototype.finally called with a non-branded Promise does not throw
|
||||
esid: sec-promise.prototype.finally
|
||||
features: [Promise.prototype.finally]
|
||||
---*/
|
||||
|
||||
var called = false;
|
||||
var p = new Proxy(Promise.resolve(), {});
|
||||
var oldThen = Promise.prototype.then;
|
||||
Promise.prototype.then = () => { called = true; };
|
||||
Promise.prototype.finally.call(p);
|
||||
assert.sameValue(called, true);
|
||||
Promise.prototype.then = oldThen;
|
Loading…
Reference in New Issue