Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Nov 21, 2019
1 parent a3c5307 commit 2d90a04
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
34 changes: 34 additions & 0 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,38 @@ describe('<Autocomplete />', () => {
expect(textbox.value).to.equal('');
});
});

describe('prop: filterOptions', () => {
it('should ignore object keys by default', () => {
const { queryAllByRole, getByRole } = render(
<Autocomplete
options={[
{
value: 'one',
label: 'One',
},
{
value: 'two',
label: 'Two',
},
]}
getOptionLabel={option => option.name}
renderInput={params => <TextField autoFocus {...params} />}
/>,
);
let options
const textbox = getByRole('textbox');

options = queryAllByRole('option');
expect(options.length).to.equal(2);

fireEvent.change(textbox, { target: { value: 'value' } });
options = queryAllByRole('option');
expect(options.length).to.equal(0);

fireEvent.change(textbox, { target: { value: 'one' } });
options = queryAllByRole('option');
expect(options.length).to.equal(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ function defaultStringify(value) {
if (value == null) {
return '';
}

if (typeof value === 'string') {
return value;
}

if (typeof value === 'object') {
return Object.keys(value)
.map(key => value[key])
.join(' ');
}

return JSON.stringify(value);
}
export function createFilterOptions(config = {}) {
Expand Down

0 comments on commit 2d90a04

Please sign in to comment.