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

Tests for Promise.withResolvers #3910

Open
4 of 14 tasks
peetklecha opened this issue Sep 8, 2023 · 4 comments
Open
4 of 14 tasks

Tests for Promise.withResolvers #3910

peetklecha opened this issue Sep 8, 2023 · 4 comments

Comments

@peetklecha
Copy link
Contributor

peetklecha commented Sep 8, 2023

I was asked to open this issue to track test completeness for the Stage 3 Promise.withResolvers method. I'm pretty new to this so any suggestions for things that should go in this tracker would be very appreciated.

  • boilerplate tests (e.g., length.js, name.js, prop-desc.js, not-a-constructor.js, builtin.js)
  • throws a type error if receiver is not a constructor
  • produces an object with the Object.prototype prototype
  • produces an object with the keys resolve, reject, and promise
  • the value of the promise property on the produced object is an instance of the receiver
  • the values of the resolve and reject properties are both 1-place functions
  • Receiver constructor does not have to extend built-in Promise
  • Function body of the receiver constructor
    • throws
    • TypeError if it passes only zero or one parameter to the executor (because we can't get a resolve or reject)
    • nothing happens if it passes more than 2 parameters to the executor
    • TypeError if it passes a non-callable resolve to the executor
    • TypeError if it passes a non-callable reject to the executor
    • TypeError if it calls the executor twice
    • value of promise property if it returns a value that isn't an instance of itself
@ptomato
Copy link
Contributor

ptomato commented Sep 8, 2023

Thanks! Added some suggestions from examining the existing tests for Promise.all.

@evilpie
Copy link
Contributor

evilpie commented Sep 19, 2023

Assuming the built-ins/Promise/withResolvers directory contains all tests, what I am missing is test(s) that call the resolve/reject functions and make sure the promise object is correctly rejected/resolved.

@peetklecha
Copy link
Contributor Author

thanks for the additions @ptomato ! i'm not sure i understand the first or last items in the sub-list you added there.

also do you know of an example of an existing Promise method that has a test for Reciever constructor does not have to extend built-in Promise?

@ptomato
Copy link
Contributor

ptomato commented Oct 2, 2023

Sure, for the first item in the sub-list ("throws"): I meant we should test the case where the function body of the receiver's constructor throws an exception. Like this:

function MyPromise() {
  throw new Error("you can't call me");
}
Promise.withResolvers.call(MyPromise);

For the last item in the sub-list ("value of promise property if it returns a value that isn't an instance of itself") - since a constructor can override the object that it would normally return, and return an entirely different object that isn't an instance of that constructor, or isn't even a Promise. Like this:

class MyPromise extends Promise {
  constructor(...args) {
    super(...args);
    return { then: Promise.prototype.then };
  }
}
Promise.withResolvers.call(MyPromise);

For an existing example of "Reciever constructor does not have to extend built-in Promise" I don't know of one. But I did find https://github.com/tc39/test262/blob/main/test/built-ins/Promise/all/S25.4.4.1_A4.1_T1.js which is a test for the opposite, that Promise.all() fails when the receiver doesn't extend built-in Promise. So maybe I'm missing something in my reading of the spec for Promise.withResolvers(), and this should actually not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants