{"record":{"id":"5dc668919baaedae","repo":"facebook/react","slug":"expected-1-but-found-all-length-instances-mes","errorCode":null,"errorMessage":"Expected 1 but found ${all.length} instances ${message}","messagePattern":"Expected 1 but found (.+?) instances (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-test-renderer/src/ReactTestRenderer.js","lineNumber":456,"sourceCode":"  });\n\n  return results;\n}\n\nfunction expectOne(\n  all: Array<ReactTestInstance>,\n  message: string,\n): ReactTestInstance {\n  if (all.length === 1) {\n    return all[0];\n  }\n\n  const prefix =\n    all.length === 0\n      ? 'No instances found '\n      : `Expected 1 but found ${all.length} instances `;\n\n  throw new Error(prefix + message);\n}\n\nfunction propsMatch(props: Object, filter: Object): boolean {\n  for (const key in filter) {\n    if (props[key] !== filter[key]) {\n      return false;\n    }\n  }\n  return true;\n}\n\nfunction create(\n  element: React$Element<any>,\n  options: TestRendererOptions,\n): {\n  _Scheduler: typeof Scheduler,\n  root: void,\n  toJSON(): Array<ReactTestRendererNode> | ReactTestRendererNode | null,","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-test-renderer/src/ReactTestRenderer.js#L438-L474","documentation":"The singular query helpers on ReactTestInstance (find, findByType, findByProps) require exactly one match; expectOne throws 'Expected 1 but found N instances ...' when the predicate matches several rendered instances, listing the query in the message suffix.","triggerScenarios":"Calling findByType(Component)/findByProps({...}) when the tree contains two or more matching instances, such as a component rendered in a list or in both a desktop and mobile branch.","commonSituations":"A list renders the same child type multiple times; a component appears in both a header and body slot; props filter is too loose (e.g. matching on a className shared by many nodes).","solutions":["Narrow the query: add distinguishing props and use findByProps({type: X, ...}) instead of findByType","Switch to findAllByType(Component) and pick the specific index you mean, asserting the expected count","Query through a parent instance (parent.findByType) to scope the search to one subtree"],"exampleFix":"// before\nconst input = root.findByType('input'); // throws: Expected 1 but found 3 instances\n\n// after\nconst inputs = root.findAllByType('input');\nexpect(inputs).toHaveLength(3);\nconst email = root.findByProps({type: 'email'});","handlingStrategy":"validation","validationCode":"// Assert cardinality explicitly, then pick the instance you mean\nconst buttons = root.findAllByType(Button);\nassert.equal(buttons.length, 3, `expected 3 Buttons, got ${buttons.length}`);\nconst primary = root.findByProps({variant: 'primary'});","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add distinguishing props to queried components instead of relying on type uniqueness","Scope queries to a parent instance (parent.findByType) when a type repeats across the tree"],"tags":["testing","react-test-renderer","find-by-type","query-multiple-matches"],"backgroundTag":"test-query-multiple-matches","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}