Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Feb 19, 2020
1 parent 45c4d78 commit 0bd00e0
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js
Expand Up @@ -736,6 +736,36 @@ describe('<Autocomplete />', () => {
'For the input option: "a", `getOptionLabel` returns: undefined',
);
});

it('warn if getOptionSelected match multiple values for a given option', () => {
const value = [{ id: '10', text: 'One' }, { id: '20', text: 'Two' }];
const options = [
{ id: '10', text: 'One' },
{ id: '20', text: 'Two' },
{ id: '30', text: 'Three' },
];

render(
<Autocomplete
{...defaultProps}
multiple
options={options}
value={value}
getOptionLabel={option => option.text}
getOptionSelected={option => value.find(v => v.id === option.id)}
renderInput={params => <TextField {...params} autoFocus />}
/>,
);

fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });
fireEvent.keyDown(document.activeElement, { key: 'ArrowDown' });
fireEvent.keyDown(document.activeElement, { key: 'Enter' });

expect(consoleErrorMock.callCount()).to.equal(1); // strict mode renders twice
expect(consoleErrorMock.args()[0][0]).to.include(
'The component expects a single value to match a given option but found 2 matches.',
);
});
});

describe('prop: options', () => {
Expand Down

0 comments on commit 0bd00e0

Please sign in to comment.