From 7f751dc9f947fe870b8e03e8731ecd0159aa5aa1 Mon Sep 17 00:00:00 2001 From: p-pych Date: Wed, 16 Oct 2024 16:48:07 +0200 Subject: [PATCH] added info about workaround for testing --- docs/data/material/components/rating/rating.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/data/material/components/rating/rating.md b/docs/data/material/components/rating/rating.md index c6b0e8cc2a99a5..ceb79991915e65 100644 --- a/docs/data/material/components/rating/rating.md +++ b/docs/data/material/components/rating/rating.md @@ -12,6 +12,19 @@ githubSource: packages/mui-material/src/Rating

Ratings provide insight regarding others' opinions and experiences, and can allow the user to submit a rating of their own.

{{"component": "@mui/docs/ComponentLinkHeader"}} +:::warning + +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. + +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