add tests for Promise.withResolvers proposal

This commit is contained in:
Peter Klecha 2023-07-05 14:47:51 -04:00 committed by Philip Chimento
parent e04e1c1a39
commit 81ba258677
7 changed files with 107 additions and 0 deletions

View File

@ -108,6 +108,10 @@ json-parse-with-source
# https://github.com/tc39/proposal-iterator-helpers
iterator-helpers
# Promise.withResolvers
# https://github.com/tc30/proposal-promise-with-resolvers
promise-with-resolvers
## Standard language features
#
# Language features that have been included in a published version of the

View File

@ -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 produces instances of the reciever
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);

View File

@ -0,0 +1,11 @@
// 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 reciever is not a constructor
features: [promise-with-resolvers]
---*/
assert.throws(TypeError, function() {
Promise.withResolvers.call(eval);
});

View File

@ -0,0 +1,31 @@
// 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
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());
});

View File

@ -0,0 +1,14 @@
// 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
features: [promise-with-resolvers]
---*/
var instance = Promise.withResolvers();
assert.sameValue(instance.promise.constructor, Promise);
assert.sameValue(instance.promise instanceof Promise, true);

View File

@ -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 properties called "resolve" and "reject" which are unary functions
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');

View File

@ -0,0 +1,17 @@
// 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"
features: [promise-with-resolvers]
---*/
var instance = Promise.withResolvers();
assert.sameValue(typeof instance, "object");
assert.notSameValue(instance, null);
assert(Object.hasOwn(instance, "promise"));
assert(Object.hasOwn(instance, "resolve"));
assert(Object.hasOwn(instance, "reject"));