-
Notifications
You must be signed in to change notification settings - Fork 561
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
Add tests for '@reach/utils' and compatibility check with react 18 #960
base: dev
Are you sure you want to change the base?
Conversation
…al/test instead of @testing-library/react
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9af9a61:
|
); | ||
lastActiveElement.current = ownerDocument.activeElement; | ||
if ( | ||
when === "focus" && |
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.
If do not check it and try use this hook with blur
, handleChange will never be called, because ownerDocument.activeElement
will be always ownerDocument.body
.
} | ||
|
||
ownerDocument.addEventListener(when, onChange, true); | ||
|
||
return () => { | ||
ownerDocument.removeEventListener(when, onChange); | ||
ownerDocument.removeEventListener(when, onChange, true); |
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.
removing the handler didn't work before.
demo: https://codepen.io/dartess/pen/rNdgWEj
Hi.
I covered all the hooks with tests, except for
useIsomorphicLayoutEffect
(I have no idea what and how to honestly test there). I don’t see the point in covering individual helpers within this task with tests, mostly they are too simple and/or do not rely to React.In some hooks, I found problems that I fixed:
useFocusChange
that commented below;useLazyRef
- unnecessarily usedany
;useUpdateEffect
- the cleanup return from the effect was missed, the effects were not cleaned.I also checked the work of all tests in
StrictMode
(includingreact@18
). One of the hooks required a rewrite - this isuseUpdateEffect
. Now it works as intended.