CodeVetter · Repo Unpack · Behavior traces
testing-library/react-testing-library
The inspected flows cover import setup, component lifecycle, hydration, events, async queries, and hooks. Each trace follows runtime functions and relevant test usage rather than assuming behavior from filenames. These walks were read from source and were not executed.
- Startup: pure-module evaluation installs DOM timer/async/event wrappers; index.js then checks RTL_SKIP_AUTO_CLEANUP, registers afterEach or teardown, and registers beforeAll/afterAll act-environment management when both hooks exist.
- Initial render: render validates options → defaults to document.body → appends a div → createConcurrentRoot calls createRoot → tracking is populated → renderRoot calls root.render inside act → query helpers are returned.
- Update and teardown: result.rerender calls renderRoot with the captured root, wrapper, and scope; result.unmount calls root.unmount in act; cleanup later walks registered roots and clears their tracking.
- Hydration: render with hydrate:true creates a concurrent root through act(hydrateRoot); renderRoot subsequently calls the adapter's no-op hydrate, and rerender later uses root.render. The hydration test then clicks the existing button and asserts updated text.
- Interaction: fireEvent.click forwards to the DOM helper; the configured eventWrapper runs its callback inside act, but nested wrapper invocations execute directly. The nesting regression dispatches input from an effect and checks both updates and act warnings.
- Async query: a fixture effect schedules a promise or timer update → the test awaits waitFor/findBy → asyncWrapper disables the act flag, awaits its callback, drains microtasks via setTimeout(0), advances detected Jest fake timers, and restores the prior flag in finally.
- Hook flow: renderHook extracts initialProps → render mounts TestComponent → renderCallback computes output → useEffect writes result.current → returned rerender calls baseRerender with new props, while unmount is inherited from render.
- Explicit act: withGlobalActEnvironment saves the prior flag and enables it; synchronous callbacks restore immediately, object thenables restore on resolution/rejection, and synchronous exceptions restore before rethrow.