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

[v15] MockedUnaryCall.then: Handle onrejected not being defined #43269

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

ravicious
Copy link
Member

While working on a v16 feature, I discovered that MockedUnaryCall behaves incorrectly when returned from a non-async function (which should be perfectly valid) #43195 (comment).

Since that PR won't be backported to v15, I'm pushing just this single fix to v15.

I copied the error branch implementation from https://www.promisejs.org/implementing/#then. It's like the second time I'm fixing this class that I wrote myself, hopefully this is the last time! 🤞

I just copied stuff from the linked implementation of then.
@ravicious ravicious added the no-changelog Indicates that a PR does not require a changelog entry label Jun 20, 2024
@ravicious ravicious requested a review from gzdunek June 20, 2024 10:06
@github-actions github-actions bot requested a review from nklaassen June 20, 2024 10:06
@ravicious ravicious requested review from ryanclark and removed request for nklaassen June 20, 2024 10:07
@ravicious ravicious enabled auto-merge June 20, 2024 10:07
try {
// Despite this being an error branch, it needs to use Promise.resolve. Otherwise we'd get
// uncaught errors. See https://www.promisejs.org/implementing/#then
return Promise.resolve(onrejected(this.error));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually, it makes total sense that this needs to be Promise.resolve(onrejected(…)).

If you have something like this:

Promise.reject().then(() => { /* onfulfilled */ }, () => { /* onrejected */)

and onrejected doesn't reject itself, the final promise you get is fulfilled, not rejected.

@ravicious
Copy link
Member Author

@ryanclark ping

@ravicious ravicious added this pull request to the merge queue Jul 1, 2024
Merged via the queue into branch/v15 with commit 1de7e8f Jul 1, 2024
32 of 33 checks passed
@ravicious ravicious deleted the r7s/v15/mockedunarycall-err branch July 1, 2024 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport no-changelog Indicates that a PR does not require a changelog entry size/sm ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants