Skip to content
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

[Tech debt] Remove testCustomHook in favor of RTL renderHook #7260

Merged
merged 12 commits into from
Oct 9, 2023

Conversation

cee-chen
Copy link
Member

@cee-chen cee-chen commented Oct 6, 2023

Summary

Twas the turn of the year of our lawd 2022, and EUI had not yet heard the good word of RTL. At the time, I wanted a way to quickly and easily unit test custom hooks and I made this horrifyingly janky DIY util to do so.

Thankfully, @testing-library actually has a fully fledged and battle-tested renderHook util that is much better in almost every measurable way (https://react-hooks-testing-library.com/reference/api), and that we've already started using in other places.

This PR rips out old instances of testCustomHook and replaces them with the renderHook API, and rids us of my jank 4eva.

QA

If CI passes, we should be good to go 🤞

General checklist

N/A, tests/tech debt only only

- it's not rendering any jsx, so no need to use `.tsx`
- tests where the syntax is a straightforward conversion to `result.current`
- they're now typed properly by `renderHook`, so doing some mionr DRYing out here
…een tests

- RTL auto-cleans up state between tests (https://testing-library.com/docs/react-testing-library/setup/#skipping-auto-cleanup) so tests on Enzyme that were expecting state to be preserved are now failing, and need to be updated

For tests that can import directly from `@testing-library/react`, `/pure` is an option to not clear state between tests
- use a common `getRender` util for asserting on rendered content
- make it all one test instead of 3 different ones since state is resetting between tests

- skip a test util since we're rerendering
@cee-chen cee-chen added testing Issues or PRs that only affect tests - will not need changelog entries skip-changelog tech debt labels Oct 6, 2023
@cee-chen cee-chen changed the title [Tech debt] Remove DIY testCustomHook in favor of RTL renderHook [Tech debt] Remove testCustomHook in favor of RTL renderHook Oct 6, 2023
@cee-chen cee-chen marked this pull request as ready for review October 6, 2023 20:22
@cee-chen cee-chen requested a review from a team as a code owner October 6, 2023 20:22
@kibanamachine
Copy link

Preview staging links for this PR:

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

Copy link
Contributor

@1Copenut 1Copenut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM!

@cee-chen cee-chen merged commit cde5b3e into elastic:main Oct 9, 2023
2 checks passed
@cee-chen cee-chen deleted the tests/render-hook-cleanup branch October 9, 2023 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog tech debt testing Issues or PRs that only affect tests - will not need changelog entries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants