{"record":{"id":"44af2b14c441dff5","repo":"emotion-js/emotion","slug":"could-not-get-unrendered-element-reliably-from-the","errorCode":null,"errorMessage":"Could not get unrendered element reliably from the Enzyme's ShallowWrapper. This is a bug in Emotion - please open an issue with repro steps included:\nhttps://github.com/emotion-js/emotion/issues/new?assignees=&labels=bug%2C+needs+triage&template=--bug-report.md&title=","messagePattern":"Could not get unrendered element reliably from the Enzyme's ShallowWrapper\\. This is a bug in Emotion - please open an issue with repro steps included:\nhttps://github\\.com/emotion-js/emotion/issues/new\\?assignees=&labels=bug%2C\\+needs\\+triage&template=--bug-report\\.md&title=","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest/src/create-enzyme-serializer.js","lineNumber":36,"sourceCode":"      return {\n        ...json,\n        children: json.children.slice(-1)\n      }\n    }\n    return json\n  }\n})\n\n// this is a hack, leveraging the internal/implementation knowledge about the enzyme's ShallowWrapper\n// there is no sane way to get this information otherwise though\nconst getUnrenderedElement = shallowWrapper => {\n  const symbols = Object.getOwnPropertySymbols(shallowWrapper)\n  const elementValues = symbols.filter(sym => {\n    const val = shallowWrapper[sym]\n    return !!val && val.$$typeof === Symbol.for('react.element')\n  })\n  if (elementValues.length !== 1) {\n    throw new Error(\n      \"Could not get unrendered element reliably from the Enzyme's ShallowWrapper. This is a bug in Emotion - please open an issue with repro steps included:\\n\" +\n        'https://github.com/emotion-js/emotion/issues/new?assignees=&labels=bug%2C+needs+triage&template=--bug-report.md&title='\n    )\n  }\n  return shallowWrapper[elementValues[0]]\n}\n\nconst wrappedEnzymeSerializer = {\n  test: enzymeToJsonSerializer.test,\n  print: (enzymeWrapper, printer) => {\n    const isShallow = !!enzymeWrapper.dive\n\n    if (isShallow && enzymeWrapper.root() === enzymeWrapper) {\n      const unrendered = getUnrenderedElement(enzymeWrapper)\n      if (\n        isEmotionCssPropElementType(unrendered) ||\n        isStyledElementType(unrendered)\n      ) {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/emotion-js/emotion/blob/b882bcba85132554992e4bd49e94c95939bbf810/packages/jest/src/create-enzyme-serializer.js#L18-L54","documentation":"create-enzyme-serializer's getUnrenderedElement inspects Enzyme ShallowWrapper's internal symbol properties to find exactly one React element. If zero or multiple element-valued symbols are found, the internals could not be interpreted reliably, so it throws and asks for a bug report. This usually means the Enzyme version's internals no longer match what emotion's serializer expects.","triggerScenarios":"Calling toHaveStyleRule / toMatchEmotionSnapshot on an Enzyme shallow() wrapper when Object.getOwnPropertySymbols(wrapper) yields a count of React-element-typed values other than exactly 1 — typically with incompatible Enzyme or React versions.","commonSituations":"Upgrading React or Enzyme so ShallowWrapper internals changed; shallow-rendering a component that renders fragments/multiple roots; using a wrapper type emotion's serializer doesn't support.","solutions":["Pin compatible versions of enzyme, enzyme-adapter-react-* and @emotion/jest / jest-emotion","Pass the rendered root element (or use mount) instead of the ShallowWrapper when testing styles","Render only a single root element from the component under test","Open an emotion issue with repro steps as the message requests if versions are current"],"exampleFix":"// before\nconst wrapper = shallow(<MyButton />)\nexpect(wrapper).toHaveStyleRule('color', 'red')\n\n// after\nconst wrapper = mount(<MyButton />)\nexpect(wrapper.find('button')).toHaveStyleRule('color', 'red')","handlingStrategy":"validation","validationCode":"function hasSingleReactElement(wrapper) {\n  const syms = Object.getOwnPropertySymbols(wrapper)\n  const count = syms.filter(s => {\n    const v = wrapper[s]\n    return !!v && v.$$typeof === Symbol.for('react.element')\n  }).length\n  return count === 1\n}","typeGuard":"function isReactElement(v) {\n  return !!v && v.$$typeof === Symbol.for('react.element')\n}","tryCatchPattern":null,"preventionTips":["Pin enzyme/adapter versions tested against @emotion/jest","Shallow-render components with exactly one root element","Prefer mount + element selection over passing ShallowWrapper directly"],"tags":["enzyme","jest","serialization","version-mismatch"],"backgroundTag":"library-internals-mismatch","analyzedSha":"b882bcba85132554992e4bd49e94c95939bbf810","analyzedAt":"2026-09-02T22:27:13.739Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}