-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
[ButtonBase] Improve test coverage #16361
Conversation
@@ -9,7 +9,7 @@ import { | |||
|
|||
export interface ButtonBaseTypeMap { | |||
props: { | |||
action?: (actions: ButtonBaseActions) => void; | |||
action?: React.Ref<ButtonBaseActions>; |
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.
This is passed to useImperativeHandle
.
This comment has been minimized.
This comment has been minimized.
ed7b707
to
f05ab36
Compare
DragEvents cant be constructed
were required for top level refs in enzyme
e08538a
to
8f36d59
Compare
No bundle size changes comparing ed4a76c...cc69b86 |
still requires enzyme. Should be TouchRippleProps={{ center: true }} instead
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.
How was your experience moving the tests from enzyme to testing-library?
}; | ||
} | ||
|
||
const fireEvent = Object.assign(rtlFireEvent, { | ||
// polyfill event.key for chrome 49 (supported in Material-UI v4) |
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.
Would using react-dom/test-utils
solve the issue?
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.
They don't create native events for you but dispatch a given one. I haven't looked for a package that creates "old events" ergonomically. I couldn't even find a way to create events in chrome 49 manually without react failing to identify the key.
It seems like key
is the prioritized property by react to create the synthetic event which makes this the simplest solution.
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.
So using react-dom/test-utils
doesn't have an impact on how React polyfills the events.
What allowed the tests to pass previously in Chrome 49?
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 wasn't an actual event just something that matched it structurally for the important parts. It works most of the time since we're not interested in the full event object but it makes the test a bit more robust against implementation changes while they are more brittle towards browser implementation.
I would definitely rethink this if we would support more older browsers but since it's only chrome 49 and we will likely phase that out in v5 I'm comfortable with that.
It also raises awareness about behavior that would require user/dev action in certain browsers like enabling touch events in edge.
Learned a bit about the DOM. Writing experience was pleasant since vscode works really well with typed libraries. Whenever I made a mistake refactoring the proper expect matchers helped identify the problem without me having to add another console.log.
so you immediately know you should've used Some things are obviously hard like the Tests are now more descriptive and it's easier with them to explain to someone how something should behave i.e. every time you do something that nobody will ever do in their codebase/browser you leave some question marks. It's obviously easier in some cases like All we can do is try to improve instead of giving up immediately because it won't be perfect. |
Forgot to add the 1: Going back and forth whether |
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.
Sweet, thanks for sharing the journey.
Turns out I was wrong about that. The documentation for |
All these points are coupled together (rtl is a bit more type friendly to the new testing approach, rtl enables new test etc).
Enables thinking about when to test for DOM properties vs HTML attributes so that was good practice.