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

[docs][Rating] Added info about workaround for testing #44129

Closed
wants to merge 1 commit into from

Conversation

p-pych
Copy link

@p-pych p-pych commented Oct 16, 2024

Closes: 38828

@mui-bot
Copy link

mui-bot commented Oct 16, 2024

Netlify deploy preview

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 7f751dc


Testing with `@testing-library/user-event`

When using `@testing-library/user-event` for testing the `Rating` component, you may encounter an issue where `onChange` returns `NaN`. This happens because the mouse event simulations rely on `getBoundingClientRect`, which returns default values (zeros) in Jest.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
When using `@testing-library/user-event` for testing the `Rating` component, you may encounter an issue where `onChange` returns `NaN`. This happens because the mouse event simulations rely on `getBoundingClientRect`, which returns default values (zeros) in Jest.
When using `@testing-library/user-event` for testing the `Rating` component, you may encounter an issue where `onChange` returns `NaN`. This happens because the mouse event simulations rely on `getBoundingClientRect`, which returns default values (zeros) in jsdom.

@@ -12,6 +12,19 @@ githubSource: packages/mui-material/src/Rating
<p class="description">Ratings provide insight regarding others' opinions and experiences, and can allow the user to submit a rating of their own.</p>

{{"component": "@mui/docs/ComponentLinkHeader"}}
:::warning
Copy link
Member

@oliviertassinari oliviertassinari Oct 16, 2024

Choose a reason for hiding this comment

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

This isn't going to happen, not here at the top of the file 😄

Copy link
Author

Choose a reason for hiding this comment

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

Sure thing. Where should i place it then ? At the bottom ? Could you suggest a place for it. Should i use a warning ?
Let me know i'll add suggested changes and move it around.

@zannager zannager added docs Improvements or additions to the documentation component: rating This is the name of the generic UI component, not the React module! labels Oct 17, 2024
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

@DiegoAndai How do you think we should proceed here considering this #38828 (comment)?

My suggestion is that developers should check the source code and we shouldn't document this. Adding a workaround to the docs risks becoming outdated as the implementation evolves. Developers encountering this issue should be encouraged to consult the source code for testing strategies, which is actively maintained and verified in CI.

@DiegoAndai
Copy link
Member

I agree with #38828 (comment) and with @ZeeshanTamboli. Closing as not planned.

@p-pych, thanks for contributing, and sorry that this PR didn't get merged. If you wish to continue to work on this issue, that would be great! Please read #38828 (comment) for next steps and let us know.

@DiegoAndai DiegoAndai closed this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: rating This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[docs][Rating] Testing the component with @testing-library/user-event results in NaN
6 participants