-
Notifications
You must be signed in to change notification settings - Fork 535
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
Upstream useSafeTimeout & add tests #1041
Conversation
🦋 Changeset detectedLatest commit: 0a392a0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/primer/primer-components/q1oh7cujf |
…o upstream-behaviors
@@ -0,0 +1,33 @@ | |||
import {useCallback, useEffect, useRef} from 'react' | |||
|
|||
type SetTimeout = (handler: TimerHandler, timeout?: number, ...args: any[]) => number |
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.
Same suggestion about using typeof window.setTimeout
as above.
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.
I tried that, but there are some required properties on the native type that doesn't make sense to pass in manually to these wrapper functions:
Property '__promisify__' is missing in type '(handler: TimerHandler, timeout?: number | undefined, ...args: any[]) => number' but required in type 'typeof setTimeout'.ts(2322)
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.
Oh weird! Thanks for checking.
import useSafeTimeout from '../hooks/useSafeTimeout' | ||
|
||
test('should call callback after time', async () => { | ||
const { result, waitFor } = renderHook(() => useSafeTimeout()) |
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.
Is there a reason for not using fake timers on this test?
Co-authored-by: Trevor Gau <t-hugs@github.com>
Note: I had to do an extensive refactoring of our tests to get them to work nicely with typescript after adding the |
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.
Nice work! Thanks for dealing with the tests ❤️ Just left a few minor comments.
Co-authored-by: Cole Bemis <colebemis@github.com>
Co-authored-by: Cole Bemis <colebemis@github.com>
Co-authored-by: Cole Bemis <colebemis@github.com>
Co-authored-by: Cole Bemis <colebemis@github.com>
Co-authored-by: Cole Bemis <colebemis@github.com>
This PR upstreams the
useSafeTimeouts
hook and adds some simple tests.I've also added documentation, including adding a new
Hooks
subsection to the documentation site 🎉 We might want to rethink how we structure the sidebar later but I think this is fine for now.Related issue: #1013
Merge checklist
index.d.ts
) if necessaryTake a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.