Skip to content

fix: configure dom-testing-library to flush Svelte changes #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025

Conversation

mcous
Copy link
Collaborator

@mcous mcous commented May 16, 2025

Overview

While working on new examples for Svelte 5, I found a problem with this library's interop with @testing-library/user-event - depending on project setup, await user.click() et. al. does not wait for Svelte to flush changes.

We were missing a call to configure to @testing-library/dom to configure the eventWrapper (for fireEvent) and asyncWrapper (for user-event) options. This fixes the issue for user-event, and happily, removes the need for an async re-export of fireEvent once we're able to drop Svelte 3/4, thanks to the new flushSync export from svelte

Related (old) issue: #250

Change log

  • Add setup function to complement cleanup function that calls @testing-library/dom::configure with tick and flushSync
  • Wire setup into beforeEach for Jest and Vitest
  • Add cleanup setup to setup docs in README

@mcous mcous force-pushed the fix/user-event-act branch 3 times, most recently from d8edb3b to 2230452 Compare May 16, 2025 20:02
@mcous mcous force-pushed the fix/user-event-act branch from 2230452 to 10f0221 Compare May 17, 2025 13:24
@mcous mcous marked this pull request as ready for review May 17, 2025 13:27
@mcous mcous merged commit 492dbd1 into main May 19, 2025
34 checks passed
@mcous mcous deleted the fix/user-event-act branch May 19, 2025 14:41
Copy link

🎉 This PR is included in version 5.2.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant