Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for Promise.withResolvers proposal #3867

Merged
merged 11 commits into from
Sep 8, 2023
4 changes: 4 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ json-parse-with-source
# https://github.com/tc39/proposal-iterator-helpers
iterator-helpers

# Promise.withResolvers
# https://github.com/tc39/proposal-promise-with-resolvers
promise-with-resolvers

## Standard language features
#
# Language features that have been included in a published version of the
Expand Down
16 changes: 16 additions & 0 deletions test/built-ins/Promise/withResolvers/ctx-ctor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2023 Peter Klecha. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Promise.withResolvers produces instances of the receiver
esid: sec-promise.withresolvers
features: [promise-with-resolvers]
---*/

class SubPromise extends Promise {}

var instance = Promise.withResolvers.call(SubPromise);

assert.sameValue(instance.promise.constructor, SubPromise);
assert.sameValue(instance.promise instanceof SubPromise, true);

12 changes: 12 additions & 0 deletions test/built-ins/Promise/withResolvers/ctx-non-ctor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2023 Peter Klecha. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Promise.withResolvers errors when the receiver is not a constructor
esid: sec-promise.withresolvers
features: [promise-with-resolvers]
---*/

assert.throws(TypeError, function() {
Promise.withResolvers.call(eval);
});
32 changes: 32 additions & 0 deletions test/built-ins/Promise/withResolvers/ctx-non-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2023 Peter Klecha. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Promise.withResolvers errors when the receiver is not an object
esid: sec-promise.withresolvers
features: [promise-with-resolvers]
---*/

assert.throws(TypeError, function() {
Promise.withResolvers.call(undefined);
});

assert.throws(TypeError, function() {
Promise.withResolvers.call(null);
});

assert.throws(TypeError, function() {
Promise.withResolvers.call(86);
});

assert.throws(TypeError, function() {
Promise.withResolvers.call('string');
});

assert.throws(TypeError, function() {
Promise.withResolvers.call(true);
});

assert.throws(TypeError, function() {
Promise.withResolvers.call(Symbol());
});
15 changes: 15 additions & 0 deletions test/built-ins/Promise/withResolvers/promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2023 Peter Klecha. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Promise.withResolvers return value has a property called "promise" which is a Promise
esid: sec-promise.withresolvers
features: [promise-with-resolvers]
---*/


var instance = Promise.withResolvers();

assert.sameValue(instance.promise.constructor, Promise);
assert.sameValue(instance.promise instanceof Promise, true);

16 changes: 16 additions & 0 deletions test/built-ins/Promise/withResolvers/resolvers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2023 Peter Klecha. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Promise.withResolvers return value has properties called "resolve" and "reject" which are unary functions
esid: sec-promise.withresolvers
features: [promise-with-resolvers]
---*/


var instance = Promise.withResolvers();

assert.sameValue(typeof instance.resolve, 'function', 'type of resolve property');
assert.sameValue(instance.resolve.length, 1, 'length of resolve property');
assert.sameValue(typeof instance.reject, 'function', 'type of reject property');
assert.sameValue(instance.reject.length, 1, 'length of reject property');
34 changes: 34 additions & 0 deletions test/built-ins/Promise/withResolvers/result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2023 Peter Klecha. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Promise.withResolvers result is an object with keys "promise", "reject", and "resolve"
esid: sec-promise.withresolvers
includes: [propertyHelper.js]
features: [promise-with-resolvers]
---*/


var instance = Promise.withResolvers();

assert.sameValue(typeof instance, "object");
assert.notSameValue(instance, null);
assert(instance instanceof Object);

verifyProperty(instance, "promise", {
writable: true,
configurable: true,
enumerable: true,
})

verifyProperty(instance, "resolve", {
writable: true,
configurable: true,
enumerable: true,
})

verifyProperty(instance, "reject", {
writable: true,
configurable: true,
enumerable: true,
})