{"record":{"id":"71a9d3522d54ff75","repo":"angular/components","slug":"select-does-not-have-options-matching-the-specifie","errorCode":null,"errorMessage":"Select does not have options matching the specified filter","messagePattern":"Select does not have options matching the specified filter","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/material/input/testing/native-select-harness.ts","lineNumber":94,"sourceCode":"    return (await this.host()).isFocused();\n  }\n\n  /** Gets the options inside the select panel. */\n  async getOptions(filter: NativeOptionHarnessFilters = {}): Promise<MatNativeOptionHarness[]> {\n    return this.locatorForAll(MatNativeOptionHarness.with(filter))();\n  }\n\n  /**\n   * Selects the options that match the passed-in filter. If the select is in multi-selection\n   * mode all options will be clicked, otherwise the harness will pick the first matching option.\n   */\n  async selectOptions(filter: NativeOptionHarnessFilters = {}): Promise<void> {\n    const [isMultiple, options] = await parallel(() => {\n      return [this.isMultiple(), this.getOptions(filter)];\n    });\n\n    if (options.length === 0) {\n      throw Error('Select does not have options matching the specified filter');\n    }\n\n    const [host, optionIndexes] = await parallel(() => [\n      this.host(),\n      parallel(() => options.slice(0, isMultiple ? undefined : 1).map(option => option.getIndex())),\n    ]);\n\n    await host.selectOptions(...optionIndexes);\n  }\n}\n","sourceCodeStart":76,"sourceCodeEnd":105,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/input/testing/native-select-harness.ts#L76-L105","documentation":"NativeSelectHarness.selectOptions(filter) fetches matching options via getOptions(filter); when none match, it throws 'Select does not have options matching the specified filter' instead of silently selecting nothing. It is a test-harness assertion that the filter matched.","triggerScenarios":"Calling harness.selectOptions({text: 'X'}) or selectOptions({index: n}) on a native select whose options do not contain that text/index, or selecting on an empty select.","commonSituations":"Options loaded asynchronously (via HTTP) after the harness query runs without waiting; filter text mismatching due to whitespace/label casing; index out of range; testing a select rendered conditionally.","solutions":["Use HarnessLoader/waitForOptions-style awaiting: ensure options are rendered before selecting (flush async with await fixture.whenStable() or fakeAsync tick).","Print available options first with getOptions() and match the exact text/index.","Correct the filter object ({text: ...} or {index: ...}) to match rendered option content.","Verify the select actually has options at the time of the call (guard with a length check before selectOptions)."],"exampleFix":"// before\nawait select.selectOptions({text: 'Option A'});\n// after\nconst options = await select.getOptions();\nif (options.length === 0) { throw new Error('select not populated yet'); }\nawait select.selectOptions({text: (await options[0].host()).textContent as string});","handlingStrategy":"validation","validationCode":"const options = await select.getOptions(filter);\nif (options.length === 0) {\n  throw new Error('No options matched filter; is the select populated yet?');\n}\nawait select.selectOptions(filter);","typeGuard":null,"tryCatchPattern":"try {\n  await select.selectOptions({text: 'Option A'});\n} catch (e) {\n  if ((e as Error).message.includes('does not have options matching')) {\n    await fixture.whenStable(); // flush async option loading\n    await select.selectOptions({text: 'Option A'});\n  } else { throw e; }\n}","preventionTips":["Await data loading (whenStable/tick) before interacting with the harness","Debug with getOptions() to see the exact rendered text/index","Keep harness filters ({text}/{index}) in sync with template option labels","Guard conditional selects: assert the select host exists before querying options"],"tags":["testing","test-harness","angular-material","native-select"],"backgroundTag":"harness-no-matching-options","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}