Skip to content

Commit 473e75e

Browse files
committed
automatically focus the input when calling selectOption
1 parent bcc8290 commit 473e75e

File tree

2 files changed

+1
-10
lines changed

2 files changed

+1
-10
lines changed

src/material/autocomplete/testing/autocomplete-harness.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ export class MatAutocompleteHarness extends ComponentHarness {
8282

8383
/** Selects the first options matching the given filters. */
8484
async selectOption(filters: OptionHarnessFilters = {}): Promise<void> {
85-
if (!await this.isOpen()) {
86-
throw Error('mat-autocomplete dropdown must be open to select an option');
87-
}
85+
await this.focus(); // Focus the input to make sure the autocomplete panel is shown.
8886
const options = await this.getOptions(filters);
8987
if (!options.length) {
9088
throw Error(`Could not find a mat-option matching ${JSON.stringify(filters)}`);

src/material/autocomplete/testing/shared.spec.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,10 @@ export function runHarnessTests(
124124

125125
it('should be able to select option', async () => {
126126
const input = await loader.getHarness(autocompleteHarness.with({selector: '#plain'}));
127-
await input.enterText('New');
128127
await input.selectOption({text: 'New York'});
129128
expect(await input.getValue()).toBe('NY');
130129
});
131130

132-
it('should throw when selecting an option if autocomplete is not open', async () => {
133-
const input = await loader.getHarness(autocompleteHarness.with({selector: '#plain'}));
134-
await expectAsyncError(() => input.selectOption({text: 'New York'}),
135-
/mat-autocomplete dropdown must be open to select an option/);
136-
});
137-
138131
it('should throw when selecting an option that is not available', async () => {
139132
const input = await loader.getHarness(autocompleteHarness.with({selector: '#plain'}));
140133
await input.enterText('New');

0 commit comments

Comments
 (0)