From 81ba2586775c758abd5e26300023cb2447fd515c Mon Sep 17 00:00:00 2001 From: Peter Klecha Date: Wed, 5 Jul 2023 14:47:51 -0400 Subject: [PATCH] add tests for Promise.withResolvers proposal --- features.txt | 4 +++ .../Promise/withResolvers/ctx-ctor.js | 15 +++++++++ .../Promise/withResolvers/ctx-non-ctor.js | 11 +++++++ .../Promise/withResolvers/ctx-non-object.js | 31 +++++++++++++++++++ .../Promise/withResolvers/promise.js | 14 +++++++++ .../Promise/withResolvers/resolvers.js | 15 +++++++++ .../built-ins/Promise/withResolvers/result.js | 17 ++++++++++ 7 files changed, 107 insertions(+) create mode 100644 test/built-ins/Promise/withResolvers/ctx-ctor.js create mode 100644 test/built-ins/Promise/withResolvers/ctx-non-ctor.js create mode 100644 test/built-ins/Promise/withResolvers/ctx-non-object.js create mode 100644 test/built-ins/Promise/withResolvers/promise.js create mode 100644 test/built-ins/Promise/withResolvers/resolvers.js create mode 100644 test/built-ins/Promise/withResolvers/result.js diff --git a/features.txt b/features.txt index b4350fea6c..57f6c83ce3 100644 --- a/features.txt +++ b/features.txt @@ -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 diff --git a/test/built-ins/Promise/withResolvers/ctx-ctor.js b/test/built-ins/Promise/withResolvers/ctx-ctor.js new file mode 100644 index 0000000000..98c2c26de0 --- /dev/null +++ b/test/built-ins/Promise/withResolvers/ctx-ctor.js @@ -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); + diff --git a/test/built-ins/Promise/withResolvers/ctx-non-ctor.js b/test/built-ins/Promise/withResolvers/ctx-non-ctor.js new file mode 100644 index 0000000000..8486fd3c53 --- /dev/null +++ b/test/built-ins/Promise/withResolvers/ctx-non-ctor.js @@ -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); +}); diff --git a/test/built-ins/Promise/withResolvers/ctx-non-object.js b/test/built-ins/Promise/withResolvers/ctx-non-object.js new file mode 100644 index 0000000000..632df54ea2 --- /dev/null +++ b/test/built-ins/Promise/withResolvers/ctx-non-object.js @@ -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()); + }); diff --git a/test/built-ins/Promise/withResolvers/promise.js b/test/built-ins/Promise/withResolvers/promise.js new file mode 100644 index 0000000000..fa6a66efc9 --- /dev/null +++ b/test/built-ins/Promise/withResolvers/promise.js @@ -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); + diff --git a/test/built-ins/Promise/withResolvers/resolvers.js b/test/built-ins/Promise/withResolvers/resolvers.js new file mode 100644 index 0000000000..c363d41363 --- /dev/null +++ b/test/built-ins/Promise/withResolvers/resolvers.js @@ -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'); diff --git a/test/built-ins/Promise/withResolvers/result.js b/test/built-ins/Promise/withResolvers/result.js new file mode 100644 index 0000000000..3d591ff8b4 --- /dev/null +++ b/test/built-ins/Promise/withResolvers/result.js @@ -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")); +