Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add support for TypeScript #8
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 support for TypeScript #8
Changes from 9 commits
7f7ca2b
ae2d990
bbfb0ff
1ba1bd9
eaee298
3cb8f92
36604a1
2bdb78a
b2478e8
a16d3a3
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Feels unnecessary to have
?
here. If theP
is inferred asundefined
, it should be ok. Otherwise, it should be required to pass the props if there were some initially to avoid surprising results.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.
Looking at the implementation of the
rerender
function, it seems thathookProps.current
is assigned as a default value. (hookProps.current
is the same asinitialProps
)https://github.com/mpeyper/react-hooks-testing-library/blob/f7cd61035d8fb08cbfac376a5a8da1780708a64e/src/index.js#L26
As long as I see this, we can call
rerender
function with no argument orinitialProps
.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 see, so it will use initialProps if none are passed. Makes sense I guess although it feels less explicit and might be confusing for tests.
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.
Correct. Subsequent rerenders will use the previously supplied props until new props are supplied.
The idea is that the props don't change until the hook is rendered with new props, so hooks that use a conditional array (i.e.
useEffect
,useLayoutEffect
,useMemo
anduseCallback
) can be reliably tested.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
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.
It'll be unnecessary someday, but it 's so smart 👍
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Where does it depend on React types actually? I don't see any reference to it.
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.
It's necessary to use React hooks in the typing test.
https://github.com/mpeyper/react-hooks-testing-library/blob/a16d3a303bfcfdd08ed007e524198b061b89d6ef/test/typescript/renderHook.ts#L1-L23