{"record":{"id":"e1c41017058e65f3","repo":"angular/components","slug":"unable-to-retrieve-options-for-autocomplete-autoc","errorCode":null,"errorMessage":"Unable to retrieve options for autocomplete. Autocomplete panel is closed.","messagePattern":"Unable to retrieve options for autocomplete\\. Autocomplete panel is closed\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/material/autocomplete/testing/autocomplete-harness.ts","lineNumber":88,"sourceCode":"  /** Whether the autocomplete input is focused. */\n  async isFocused(): Promise<boolean> {\n    return (await this.host()).isFocused();\n  }\n\n  /** Enters text into the autocomplete. */\n  async enterText(value: string): Promise<void> {\n    return (await this.host()).sendKeys(value);\n  }\n\n  /** Clears the input value. */\n  async clear(): Promise<void> {\n    return (await this.host()).clear();\n  }\n\n  /** Gets the options inside the autocomplete panel. */\n  async getOptions(filters?: Omit<OptionHarnessFilters, 'ancestor'>): Promise<MatOptionHarness[]> {\n    if (!(await this.isOpen())) {\n      throw new Error('Unable to retrieve options for autocomplete. Autocomplete panel is closed.');\n    }\n\n    return this._documentRootLocator.locatorForAll(\n      MatOptionHarness.with({\n        ...(filters || {}),\n        ancestor: await this._getPanelSelector(),\n      } as OptionHarnessFilters),\n    )();\n  }\n\n  /** Gets the option groups inside the autocomplete panel. */\n  async getOptionGroups(\n    filters?: Omit<OptgroupHarnessFilters, 'ancestor'>,\n  ): Promise<MatOptgroupHarness[]> {\n    if (!(await this.isOpen())) {\n      throw new Error(\n        'Unable to retrieve option groups for autocomplete. Autocomplete panel is closed.',\n      );","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/autocomplete/testing/autocomplete-harness.ts#L70-L106","documentation":"MatAutocompleteHarness.getOptions() locates MatOptionHarness instances inside the autocomplete panel, which only exists in the DOM while the autocomplete is open. If isOpen() reports false, the harness throws rather than returning an empty list, to signal the panel is not attached.","triggerScenarios":"Calling getOptions() (directly or via harness.getOptions(...)) before opening the autocomplete (no focus/input into the trigger), or after it closed (blur, escape, option selection).","commonSituations":"Tests that read options without first focusing the input or dispatching input events; async timing where the panel hasn't opened yet; assertions after an option was already selected which auto-closes the panel.","solutions":["Open the panel first: focus/interact with the input trigger (e.g. await (await harness.host()).sendKeys or setValue) and wait until isOpen() is true","Add a wait/flush of pending tasks (fakeAsync tick, waitFor) after triggering the input before querying options","If the panel closed after selecting an option, re-trigger it before a subsequent getOptions call"],"exampleFix":"// before\nconst options = await harness.getOptions(); // throws: panel closed\n// after\nawait harness.focus();\nawait harness.enterText('a');\nawait harness.isOpen(); // ensure true\nconst options = await harness.getOptions();","handlingStrategy":"validation","validationCode":"if (await harness.isOpen()) {\n  const options = await harness.getOptions();\n}","typeGuard":null,"tryCatchPattern":"try {\n  options = await harness.getOptions();\n} catch (e) {\n  if ((e as Error).message.includes('panel is closed')) {\n    await harness.focus(); await harness.enterText('q');\n    options = await harness.getOptions();\n  } else { throw e; }\n}","preventionTips":["Always open the autocomplete (focus/type into the trigger) before querying options","Await async rendering (tick/waitFor) after simulating input","Remember option selection closes the panel; re-open before further queries"],"tags":["angular","material","testing","component-harness","autocomplete","state-error"],"backgroundTag":"panel-closed","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}