Skip to content

feat(material/autocomplete): add clear method to test harness #24752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/material/autocomplete/testing/autocomplete-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export abstract class _MatAutocompleteHarnessBase<
return (await this.host()).sendKeys(value);
}

/** Clears the input value. */
async clear(): Promise<void> {
return (await this.host()).clear();
}

/** Gets the options inside the autocomplete panel. */
async getOptions(filters?: Omit<OptionFilters, 'ancestor'>): Promise<Option[]> {
if (!(await this.isOpen())) {
Expand Down
8 changes: 8 additions & 0 deletions src/material/autocomplete/testing/shared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ export function runHarnessTests(
expect(await input.getValue()).toBe('Hello there');
});

it('should be able to clear the input', async () => {
const input = await loader.getHarness(autocompleteHarness.with({selector: '#plain'}));
await input.enterText('Hello there');
expect(await input.getValue()).toBe('Hello there');
await input.clear();
expect(await input.getValue()).toBe('');
});

it('should be able to get the autocomplete panel options', async () => {
const input = await loader.getHarness(autocompleteHarness.with({selector: '#plain'}));
await input.focus();
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/material/autocomplete-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export abstract class _MatAutocompleteHarnessBase<OptionType extends ComponentHa
with: (options?: OptionGroupFilters) => HarnessPredicate<OptionGroup>;
}, OptionGroup extends ComponentHarness, OptionGroupFilters extends BaseHarnessFilters> extends ComponentHarness {
blur(): Promise<void>;
clear(): Promise<void>;
enterText(value: string): Promise<void>;
focus(): Promise<void>;
getOptionGroups(filters?: Omit<OptionGroupFilters, 'ancestor'>): Promise<OptionGroup[]>;
Expand Down