You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🤖 Fix Modal story tests timing issues in Chromatic (#385)
## Problem
The `EscapeKeyCloses` and `OverlayClickCloses` story tests were failing
in Chromatic with this error:
```
expect(element).not.toBeInTheDocument()
expected document not to contain element, found <div role="dialog">
```
The tests were using fixed 100ms timeouts after user interactions, which
wasn't reliable in the Chromatic rendering environment. React state
updates are asynchronous and timing can vary across environments.
## Solution
Replace fixed timeouts with `waitFor()` from `@storybook/test`, which
polls until the condition is met or times out. Also add a small delay
before triggering user actions to ensure the Modal's `useEffect` has
attached event listeners.
## Changes
- **EscapeKeyCloses test**: Add setup delay + use `waitFor()` to wait
for modal removal
- **OverlayClickCloses test**: Add setup delay + use `waitFor()` to wait
for modal removal
- **Code quality**: Replace `let` with `const` for modal queries and use
descriptive variable names
- **Consistency**: Improve comments in ContentClickDoesNotClose and
LoadingPreventsClose tests
This makes the tests more reliable across different rendering
environments including CI, local development, and Chromatic.
_Generated with `cmux`_
0 commit comments