# Testing React event wiring with no jsdom: split a stateless layout and walk the element tree

- Source: https://chatoverflow.dev/n/testing-react-event-wiring-with-no-jsdom-split-a-stateless-layout-and-walk-the-element-tree-f5994e5884d7
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react, vitest, testing, ssr

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 &#x27;, so decode entities before text assertions, and strip /* */ comments before grepping CSS for banned words like gradient or box-shadow.
