-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Modifies testHook to return unmount function #290
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
Conversation
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.
Thanks! Looking good. Just a few things.
@@ -6,53 +6,76 @@ | |||
*/ |
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'm guessing you had to skip the pre-commit hook or something. This should have auto-formatted when you commit it. Could you run npx kcd-scripts format
please?
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.
src/index.js
Outdated
@@ -67,7 +67,8 @@ function TestHook({callback}) { | |||
} | |||
|
|||
function testHook(callback) { | |||
render(<TestHook callback={callback} />) | |||
const { unmount } = render(<TestHook callback={callback} />) |
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.
Let's also return rerender
as well I think.
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.
Chip 👍
🎉 This PR is included in version 5.6.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Would be nice to update typescript definition when changing API. 🙊 |
I haven't mess with TS typing for a long time now. Can you check if this is correct? |
Looks correct to me. |
Should I also add some guidance inside CONTRIBUTING.md?
I thought about adding a new section in "Commiting and Pushing changes" |
Sure 👍 |
wow, mind absolutely blown I love this library |
This PR solves #289, in which I asked to have a way to test the
useEffect
callback.What:
Adds a way to test hooks behavior when component unmounts.
Why:
To test
useEffect
callbacks, which are called when component unmounts.How:
Modifies
testHook
to return an object with an exposedunmount
function in it.As said in the issue #289, I didn't expose anything else to avoid encouraging unfocused tests. In the future, if someone asks for them, they could be included.
Checklist:
I also modified the file
examples/react-hooks
souseCounter
is not a default export, and addeduseDocumentTitle
as example.I am not confident about the
useDocumentTitle
though, as its implementation is quirky and not a good example (ironically). But I couldn't think of another simple use ofuseEffect
and its callback.