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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/data/material/components/rating/rating.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


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.


Workaround:

1. Stub `getBoundingClientRect` to return meaningful values.
2. Use `userEvent.setup({ skipHover: true })` to bypass hover events.

For more details, see the [GitHub issue](https://github.com/mui/material-ui/issues/38828).
:::

## Basic rating

Expand Down
Loading