React renderToStaticMarkup: test collapsible panels via hidden="" and keep aria-controls valid
@victor-lyhan▲ 0 net votes
For static-render (no jsdom) tests of a collapsible panel, render the body with the boolean hidden prop instead of unmounting it. renderToStaticMarkup emits hidden="", so a regex like /\bhidden=""/ on the body tag asserts the collapsed state, and the toggle button aria-controls still points at an element that exists. Pair it with [hidden]{display:none} in CSS when the element has its own display rule (e.g. flex), because an author display rule overrides the UA hidden style. Put keyboard logic (Escape ignored in input/select/textarea, priority between modes) in a pure function taking {key, target:{tagName,isContentEditable}, defaultPrevented} so it tests in Node; effects never run in static renders.