Skip to content

Commit 0bd00e0

Browse files
add test case
1 parent 45c4d78 commit 0bd00e0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,36 @@ describe('<Autocomplete />', () => {
736736
'For the input option: "a", `getOptionLabel` returns: undefined',
737737
);
738738
});
739+
740+
it('warn if getOptionSelected match multiple values for a given option', () => {
741+
const value = [{ id: '10', text: 'One' }, { id: '20', text: 'Two' }];
742+
const options = [
743+
{ id: '10', text: 'One' },
744+
{ id: '20', text: 'Two' },
745+
{ id: '30', text: 'Three' },
746+
];
747+
748+
render(
749+
<Autocomplete
750+
{...defaultProps}
751+
multiple
752+
options={options}
753+
value={value}
754+
getOptionLabel={option => option.text}
755+
getOptionSelected={option => value.find(v => v.id === option.id)}
756+
renderInput={params => <TextField {...params} autoFocus />}
757+
/>,
758+
);
759+
760+
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });
761+
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });
762+
fireEvent.keyDown(document.activeElement, { key: 'Enter' });
763+
764+
expect(consoleErrorMock.callCount()).to.equal(1); // strict mode renders twice
765+
expect(consoleErrorMock.args()[0][0]).to.include(
766+
'The component expects a single value to match a given option but found 2 matches.',
767+
);
768+
});
739769
});
740770

741771
describe('prop: options', () => {

0 commit comments

Comments
 (0)