cljs-tlr.render
Component rendering utilities for React Testing Library.
Provides functions to render React components into a test container, returning query utilities for interacting with the rendered output.
render
(render element)(render element opts)Renders a React element and returns an object with query utilities.
The returned object provides methods like getByText, queryByRole, etc. for querying the rendered DOM. These are bound to the container where the component was rendered.
The optional options map supports:
:container- DOM element to render into (default: appends to body):base-element- Base element for queries (default: container):wrapper- Wrapper component for context providers
Example:
(let [result (render ($ my-component {:name "test"}))]
(.getByText result "Hello"))
render-hook
(render-hook hook-fn)(render-hook hook-fn opts)Renders a React hook for testing in isolation.
Takes a function that calls the hook and returns an object with:
result.current- The current return value of the hookrerender- Function to re-render with new propsunmount- Function to unmount the hook
Example:
(let [result (render-hook #(use-state 0))]
(is (= 0 (.-current (.-result result)))))
rerender
(rerender render-result element)Re-renders the component with new props.
Takes the result object from render and a new React element. Useful for testing how components respond to prop changes.
unmount
(unmount render-result)Unmounts the rendered component.
Takes the result object from render. After unmounting, the component is removed from the DOM and any effects are cleaned up.