setupRerender function configures Preact to render synchronously, making it easier to test components without dealing with asynchronous behavior.
Signature
How it works
From test-utils/src/index.js:7-11:- Saves the original
options.debounceRenderingfunction - Replaces it with a version that captures the render callback
- Returns a function that executes the captured callback
Usage
Basic setup
With state updates
Test suite setup
When to use
Use setupRerender when:
- You want fine-grained control over rendering
- You’re not using
act() - You’re writing low-level test utilities
- You need to test render timing
Use act instead when:
- You want automatic effect flushing
- You’re testing user interactions
- You’re testing async code
- You want compatibility with React testing patterns
Most tests should use
act() instead of setupRerender() directly. The act() function calls setupRerender() internally and also handles effects.teardown function
Always callteardown() after using setupRerender() to restore Preact’s default behavior:
- Flushes any pending renders
- Restores the original
debounceRenderingfunction - Cleans up test state