-
Notifications
You must be signed in to change notification settings - Fork 364
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
test: Resolve warnings and errors in Jest tests #9784
test: Resolve warnings and errors in Jest tests #9784
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.
Nice! Lots of warnings/errors are gone compared to develop
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.
A toast notification appears when an attempt by the user to download their kubeconfig fails for any reason. This failure always occurs from within this Jest test since we're not mocking the download request, and we can't make real Linode API requests via Jest.
Since the app attempts to show a toast notification, Jest logs an error because Notistack is not actually set up and available from within the context of the Jest test. This change resolves the Jest error by mocking Notistack's useSnackbar
export. However, it may be a better solution to mock the HTTP request to prevent the toast notification in the first place.
Before | After |
---|---|
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.
The AddonsPanel component makes a bunch of requests to fetch Images, but the requests aren't being mocked by MSW. This causes Jest to log ECONNREFUSED
errors for each failed HTTP request, as well as warnings from MSW relating to the unhandled requests. The fix here is to mock those GET requests to the Image endpoints.
Before | After |
---|---|
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.
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.
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.
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.
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.
We're getting a DOM validation error here because we're not wrapping the plan selection table rows in a table. Using the wrapWithTableBody
helper resolves the errors. This is a rare case where the DOM validation error is caused by the test; other DOM validation errors that get logged by React are actual issues with our component markup.
Before | After |
---|---|
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 Joe! Confirmed that the errors you commented on the specific files are gone! Also confirming that there are a lot fewer errors from yarn test 🎉
* Clean up warnings by mocking API requests * Fix longview test overlapping act() warnings * Fix PlanSelection test warning by wrapping table row components in a table body * Mock snackbar hook to resolve warning about updating state on unmounted component * Suppress React Query errors in tests where errors are expected * Added changeset: Clean up Jest warnings and errors
Description 📝
This PR aims to clean up our Jest tests a bit by resolving some of the errors and warnings that get logged to the console when running Jest. Specifically, this aims to fix issues within the tests themselves -- warnings and errors that need to be solved by modifying the source files themselves are out of scope here.
I plan to circle back tomorrow with a self review and comparison showing how the changes impact the Jest output.
How to test 🧪
We can rely on GitHub Actions for this, but you can also run the tests locally:
yarn test