-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Lens] test suite - replace React specific props events with html events #113156
[Lens] test suite - replace React specific props events with html events #113156
Conversation
Pinging @elastic/kibana-vis-editors (Team:VisEditors) |
.find('[data-test-subj="lnsIndexPatternActions-popover"]') | ||
.first() | ||
.prop('children') as ReactElement | ||
).props.items[0].props.onClick(); |
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 to mocking the portal: ReactDOM.createPortal = jest.fn((element) => element)
we can just assume that the content of the popover will be placed directly inside the popover. And thanks to that we can avoid the ugly lines above.
💚 Build SucceededMetrics [docs]
To update your PR or re-run it, just comment with: |
// wait for indx pattern to be loaded | ||
await act(async () => await new Promise((r) => setTimeout(r, 0))); |
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 am a bit on the edge of replacing this with waitFor
- I think it's more readable, but it comes from react/testing-library and we use in 99% enzyme. There are one more place where we use react-testing-library in lens (testing debouncing hook) and some other teams use it extensively in Kibana, so I am not sure. Thoughts?
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 behaviour is different between the 2 things.
I think waitFor
is more reliable than a manual arbitrary waiting. So 👍
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.
Code review 👍
// wait for indx pattern to be loaded | ||
await act(async () => await new Promise((r) => setTimeout(r, 0))); |
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 behaviour is different between the 2 things.
I think waitFor
is more reliable than a manual arbitrary waiting. So 👍
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
Summary
This is a small improvement to our test suite - most of our tests checking the correctness of the invoked events were directly invoking passed props, eg.
element.props().onClick()
. This can be improved by instead simulating user events, eg.element.simulate('click')
. This has couple of advantages:I also simplified testing the Portal created by popover. I'll leave the comment close to the code.