diff --git a/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js b/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js index b1bb46ccc4586a..61a63c7fdf3572 100644 --- a/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js +++ b/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js @@ -778,7 +778,7 @@ describe('', () => { expect(handleChange.args[0][1]).to.equal('a'); expect(consoleErrorMock.callCount()).to.equal(2); // strict mode renders twice expect(consoleErrorMock.messages()[0]).to.include( - 'For the input option: "a", `getOptionLabel` returns: undefined', + 'the `getOptionLabel` method of Autocomplete returned undefined instead of a string', ); }); diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js index d98d1650945ef9..451faed5d9aa7d 100644 --- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js +++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js @@ -197,13 +197,12 @@ export default function useAutocomplete(props) { if (process.env.NODE_ENV !== 'production') { if (typeof optionLabel !== 'string') { + const erroneousReturn = + optionLabel === undefined ? 'undefined' : `${typeof optionLabel} (${optionLabel})`; console.error( [ - 'Material-UI: the `getOptionLabel` method of useAutocomplete do not handle the options correctly.', - `The component expect a string but received ${typeof optionLabel}.`, - `For the input option: ${JSON.stringify( - newValue, - )}, \`getOptionLabel\` returns: ${optionLabel}.`, + `Material-UI: the \`getOptionLabel\` method of ${componentName} returned ${erroneousReturn} instead of a string for`, + JSON.stringify(newValue), ].join('\n'), ); } @@ -465,7 +464,7 @@ export default function useAutocomplete(props) { if (matches.length > 1) { console.error( [ - 'Material-UI: the `getOptionSelected` method of useAutocomplete do not handle the arguments correctly.', + `Material-UI: the \`getOptionSelected\` method of ${componentName} do not handle the arguments correctly.`, `The component expects a single value to match a given option but found ${ matches.length } matches.`,