-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix: correct isPromise
implementation
#13314
Conversation
packages/jest-util/src/isPromise.ts
Outdated
const isPromise = (candidate: unknown): candidate is PromiseLike<unknown> => | ||
candidate != null && | ||
(typeof candidate === 'object' || typeof candidate === 'function') && | ||
typeof (candidate as any).then === 'function'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps? Just to avoid any
? Or the point is to be explicit that this is still any
?
typeof (candidate as any).then === 'function'; | |
typeof (candidate as PromiseLike<unknown>).then === 'function'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the cast would lie - I just want to be able to access a prop. I guess as Record<string, unknown> | (...args: unknown[]) => unknown
or something is more precise looking at the typeof
checks. But not really, as typeof new Map === 'object'
. Just saying any
seems cleanest
@@ -23,3 +23,12 @@ test('a resolved Promise', () => { | |||
test('a rejected Promise', () => { | |||
expect(isPromise(Promise.reject().catch(() => {}))).toBe(true); | |||
}); | |||
|
|||
test('a thenable', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test fails with the old implementation, fwiw
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
The linked SO post says not to use it 🙈
Test plan
Green CI