{"record":{"id":"ee23585b208bc8c9","repo":"angular/components","slug":"no-active-link-could-be-found","errorCode":null,"errorMessage":"No active link could be found.","messagePattern":"No active link could be found\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/material/tabs/testing/tab-nav-bar-harness.ts","lineNumber":58,"sourceCode":"\n  /**\n   * Gets the list of links in the nav bar.\n   * @param filter Optionally filters which links are included.\n   */\n  async getLinks(filter: TabLinkHarnessFilters = {}): Promise<MatTabLinkHarness[]> {\n    return this.locatorForAll(MatTabLinkHarness.with(filter))();\n  }\n\n  /** Gets the active link in the nav bar. */\n  async getActiveLink(): Promise<MatTabLinkHarness> {\n    const links = await this.getLinks();\n    const isActive = await parallel(() => links.map(t => t.isActive()));\n    for (let i = 0; i < links.length; i++) {\n      if (isActive[i]) {\n        return links[i];\n      }\n    }\n    throw new Error('No active link could be found.');\n  }\n\n  /**\n   * Clicks a link inside the nav bar.\n   * @param filter An optional filter to apply to the child link. The first link matching the filter\n   *     will be clicked.\n   */\n  async clickLink(filter: TabLinkHarnessFilters = {}): Promise<void> {\n    const tabs = await this.getLinks(filter);\n    if (!tabs.length) {\n      throw Error(`Cannot find mat-tab-link matching filter ${JSON.stringify(filter)}`);\n    }\n    await tabs[0].click();\n  }\n\n  /** Gets the panel associated with the nav bar. */\n  async getPanel(): Promise<MatTabNavPanelHarness> {\n    const link = await this.getActiveLink();","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/tabs/testing/tab-nav-bar-harness.ts#L40-L76","documentation":"MatTabNavHarness.getActiveLink scans all links in the nav bar and returns the first whose isActive() is true; if none is active it throws 'No active link could be found.'. The harness relies on the nav bar's own active-link tracking (updateActiveLink), so the underlying link must actually be marked active.","triggerScenarios":"Calling getActiveLink() when no MatTabLink has the active state (e.g. no router link matched, or the app never called updateActiveLink / never activated a link).","commonSituations":"Router-outlet based nav bars where the current URL matches no mat-tab-link routerLink; forgetting to set an initial active link in tests; using mat-tab-link without routerLink so isActive stays false.","solutions":["Ensure one link is active (activate via router navigation or set the active state) before calling getActiveLink()","If links use routerLink, verify the test's current route matches one of them","Await router navigation / whenStable before asserting","For non-router links, call the nav bar's updateActiveLink() with the intended link"],"exampleFix":"// before\nconst active = await navHarness.getActiveLink(); // throws when none active\n\n// after\nawait router.navigate(['/first']);\nawait fixture.whenStable();\nconst active = await navHarness.getActiveLink();","handlingStrategy":"validation","validationCode":"const links = await navHarness.getLinks();\nconst anyActive = (await parallel(() => links.map(l => l.isActive()))).some(Boolean);\nif (!anyActive) await router.navigate(['/first']);","typeGuard":null,"tryCatchPattern":"try {\n  const active = await navHarness.getActiveLink();\n} catch (e) {\n  if (String(e?.message).includes('No active link')) {\n    await router.navigate(['/first']);\n    await fixture.whenStable();\n    active = await navHarness.getActiveLink();\n  }\n}","preventionTips":["Verify at least one mat-tab-link routerLink matches the current route","Navigate to a matching route before asserting active links","For non-router links, trigger updateActiveLink() explicitly","Await whenStable after navigation before harness assertions"],"tags":["angular-material","component-harness","testing","tabs"],"backgroundTag":"no-selected-element-found","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}