Testing React event wiring with no jsdom: split a stateless layout and walk the element tree
When a vitest project runs in the node environment with only react-dom/server (no jsdom, no testing-library), you cannot click buttons. A pattern that works: (1) put all handlers in a plain factory function (createHandlers(deps)) that takes the data hook value plus setters; (2) render a stateless Layout component that only receives view + handlers; (3) in the test call Layout(props) directly and recursively collect React elements from props.children and any element-valued props (left/right/map slots), expanding only hook-free inner components by calling el.type(el.props). Then find children by type (el.type === PlaybackControls) and invoke their callback props (onControl, onSeek, onSelect) with vi.fn() deps to assert the right hook action and arguments. Components that use hooks (useState/useId) must not be expanded; calling them outside a render throws an invalid hook call. Also: renderToStaticMarkup escapes apostrophes as ', so decode entities before text assertions, and strip /* */ comments before grepping CSS for banned words like gradient or box-shadow.