{"record":{"id":"176014d87fa0e71e","repo":"angular/components","slug":"the-locator-found-a-radio-group-with-name-name","errorCode":null,"errorMessage":"The locator found a radio-group with name \"${name}\", but some radio-button's within the group have mismatching names, which is invalid.","messagePattern":"The locator found a radio-group with name \"(.+?)\", but some radio-button's within the group have mismatching names, which is invalid\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/material/radio/testing/radio-harness.ts","lineNumber":160,"sourceCode":"  protected static async _checkRadioGroupName(harness: MatRadioGroupHarness, name: string) {\n    // Check if there is a radio-group which has the \"name\" attribute set\n    // to the expected group name. It's not possible to always determine\n    // the \"name\" of a radio-group by reading the attribute. This is because\n    // the radio-group does not set the \"name\" as an element attribute if the\n    // \"name\" value is set through a binding.\n    if ((await harness._getGroupNameFromHost()) === name) {\n      return true;\n    }\n    // Check if there is a group with radio-buttons that all have the same\n    // expected name. This implies that the group has the given name. It's\n    // not possible to always determine the name of a radio-group through\n    // the attribute because there is\n    const radioNames = await harness._getNamesFromRadioButtons();\n    if (radioNames.indexOf(name) === -1) {\n      return false;\n    }\n    if (!harness._checkRadioNamesInGroupEqual(radioNames)) {\n      throw Error(\n        `The locator found a radio-group with name \"${name}\", but some ` +\n          `radio-button's within the group have mismatching names, which is invalid.`,\n      );\n    }\n    return true;\n  }\n}\n\n/** Harness for interacting with a mat-radio-button in tests. */\nexport class MatRadioButtonHarness extends ComponentHarness {\n  /** The selector for the host element of a `MatRadioButton` instance. */\n  static hostSelector = '.mat-mdc-radio-button';\n\n  /**\n   * Gets a `HarnessPredicate` that can be used to search for a radio button with specific\n   * attributes.\n   * @param options Options for filtering which radio button instances are considered a match.\n   * @return a `HarnessPredicate` configured with the given options.","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/radio/testing/radio-harness.ts#L142-L178","documentation":"The radio-group locator (used by `getAllHarnesses`/`getHarness` with a `name` filter) throws when a group's host name matches the filter but its child buttons have inconsistent names. This guards against matching an invalid group whose radios are not actually grouped correctly.","triggerScenarios":"Querying `locatorFactory.getHarness(MatRadioGroupHarness.with({name: 'group1'}))` where the group host has name 'group1' but child radios carry mixed names.","commonSituations":"Same underlying DOM problem as mismatched radio names (265) but discovered during harness filtering; partially migrated templates; radios conditionally rendered with their own name.","solutions":["Make all child radio `name` attributes match the group name","Remove per-button name overrides so the group propagates its name","Fix conditional branches that render radios with divergent names"],"exampleFix":"// before\n<mat-radio-group name=\"g1\">\n  <mat-radio-button name=\"x\">A</mat-radio-button>\n</mat-radio-group>\n// after\n<mat-radio-group name=\"g1\">\n  <mat-radio-button name=\"g1\">A</mat-radio-button>\n</mat-radio-group>","handlingStrategy":"validation","validationCode":"// Before querying by name, ensure child radios share the group's name in the template:\n// <mat-radio-group name=\"group1\"><mat-radio-button name=\"group1\">A</mat-radio-button></mat-radio-group>","typeGuard":null,"tryCatchPattern":"try {\n  await harnessLoader.getHarness(MatRadioGroupHarness.with({name: 'group1'}));\n} catch (e) {\n  if (String(e?.message).includes('mismatching names')) {\n    fail(`Group 'group1' has radios with inconsistent name attributes`);\n  }\n  throw e;\n}","preventionTips":["Mirror the group's name on every child radio button","Remove leftover per-button name attributes after refactors","Run harness queries in CI to catch invalid groups early"],"tags":["angular","material","radio","testing","harness","locator"],"backgroundTag":"invalid-attribute-mismatch","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}