mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.83k stars 32.26k forks source link

[material-ui][Autocomplete] "Unable to find the input element" error while snapshot testing with react-test-renderer #40144

Open pgrabo opened 11 months ago

pgrabo commented 11 months ago

Duplicates

Latest version

Steps to reproduce πŸ•Ή

Link to live example: https://codesandbox.io/p/sandbox/reverent-worker-y7dtfw

Steps:

  1. Use Autocomplete component with renderInput prop specified as follows:
    renderInput={(params) => (
    <Tooltip title="Tooltip">
    <TextField {...params} />
    </Tooltip>
    )}
  2. Snapshot test such Autocomplete with "react-test-renderer": "18.2.0"

Current behavior 😯

Snapshot is created properly. There is following error while creating snapshot: "MUI: Unable to find the input element. It was resolved to null while an HTMLInputElement was expected. Instead, Autocomplete expects an input element.

Make sure you have customized the input component correctly."

Expected behavior πŸ€”

Snapshot is created properly. There are no errors while creating snapshot.

Context πŸ”¦

I wanted to customize Autocomplete to show the tooltip for the input/TextFileld value whenever the value is too long and ends with ellipsis. I find it usefull for the users to see the full label in the tooltip, in case it is trucated in the input.

Your environment 🌎

npx @mui/envinfo ``` System: OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish) Binaries: Node: 20.4.0 - ~/.nvm/versions/node/v20.4.0/bin/node Yarn: 1.22.4 - ~/.nvm/versions/node/v20.4.0/bin/yarn npm: 9.7.2 - ~/.nvm/versions/node/v20.4.0/bin/npm Browsers: Chrome: session. ``` Chrome version used: Version 119.0.6045.200 (Official Build) (64-bit)
mj12albert commented 10 months ago

@pgrabo Your sandbox doesn't repro the issue πŸ€” the input element seems snapshotted and logged to the console correctly:

Screenshot 2023-12-11 at 10 21 17 PM

pgrabo commented 10 months ago

mj12albert Yes, it is snapshotted and logged ok, but the issue is actually the error which is logged to the console when doing snapshot:

MUI: Unable to find the input element. It was resolved to null while an HTMLInputElement was expected.
Instead, Autocomplete expects an input element.
Make sure you have customized the input component correctly.

You can see the last line of this error in the screenshot above. Actually you did reproduced the issue. Yes, you are right, snapshot looks ok. But why mui prints this error then ? Mui tells me that I am misusing the input element, that the way I coustomized it is wrong :/

In my test environment any console error causes the test to fail (despite the fact that the snapshot might be ok) That is why this error worries me.