{"record":{"id":"46d9404318a616e2","repo":"facebook/react","slug":"no-instances-found-message","errorCode":null,"errorMessage":"No instances found ${message}","messagePattern":"No instances found (.+?)","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":"ReactTestRenderer's singular query helpers (root.find, root.findByType, root.findByProps) go through expectOne, which throws 'No instances found ...' when the predicate matches zero rendered instances. The suffix of the message describes the query (type/props) that produced no match.","triggerScenarios":"Calling testRenderer.root.findByType(Component), findByProps({foo: 'bar'}), or find(pred) when no currently rendered instance satisfies the query — e.g. the component is conditionally not rendered, or the query runs before an async state update has rendered.","commonSituations":"Component hidden behind a loading/feature condition during the query; querying inside an element that only appears after an effect or timer without awaiting act(); component identity mismatch caused by mocking (jest.mock) or duplicate React/module copies so the type never compares equal.","solutions":["Use findAllByType/findAllByProps and assert on the array length for clearer failures","Wrap the state change that renders the component in act() (or await it) so the tree is up to date before querying","Verify the component is actually rendered (check root.findAll output or the rendered JSON) and fix the condition/identity issue (same module instance, no duplicate React)"],"exampleFix":"// before\nconst button = renderer.root.findByType(Button); // throws: No instances found\n\n// after\nawait act(async () => { rerenderWithConditionTrue(); });\nconst [button] = renderer.root.findAllByType(Button);\nexpect(button).toBeDefined();","handlingStrategy":"validation","validationCode":"// Check for matches before using the singular query\nconst matches = root.findAllByType(Button);\nif (matches.length === 0) {\n  // inspect root.toJSON() to see what actually rendered\n  throw new Error('Button not rendered. Tree: ' + JSON.stringify(renderer.toJSON(), null, 2));\n}\nconst button = matches[0];","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer findAllByType/findAllByProps with explicit length assertions over the singular find* helpers","Wrap state changes in act() before querying so the tree is settled","Ensure component types compared by findByType come from the same module instance (no duplicate React copies, careful jest.mock paths)"],"tags":["testing","react-test-renderer","find-by-type","query-no-match"],"backgroundTag":"test-query-no-match","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}