-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Describe the bug
When running Vitest in browser mode, tests that trigger navigation or execute the default function of an onSubmit handler will hang indefinitely. This appears to happen because the test browser attempts to navigate away potentially causing the test runner to lose connection with the underlying node process. There doesn't seem to be clear documentation or guidance about how to handle or prevent these hangs in browser-enabled tests.
Reproduction
External reproduction: https://github.com/bteng22/vitest-browser-hangs-repro
Steps to reproduce:
- Clone the reproduction repository: https://github.com/bteng22/vitest-browser-hangs-repro
- Follow the instructions in the README to install dependencies and run the browser tests.
- Observe that when a navigation is triggered (via e.g. a form's default onSubmit), the test hangs and never completes.
Actual behaviour:
Vitest browser tests hang forever when navigation or a default onSubmit handler is triggered. The test never completes and requires manual intervention to stop. This includes programmatic navigations as well with window.location.assign or window.history.pushState
Expected behaviour:
Vitest browser tests should not hang or lose connection with the node process when navigation or form submission occurs. There should be clear documentation or built-in handling for these situations, or at least guidance on best practices for preventing such hangs in browser-enabled tests?
System Info
System:
OS: macOS 15.6.1
CPU: (16) arm64 Apple M3 Max
Memory: 322.59 MB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 23.7.0 - ~/.nvm/versions/node/v23.7.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v23.7.0/bin/npm
Browsers:
Chrome: 140.0.7339.133
Edge: 140.0.3485.66
Safari: 18.6
npmPackages:
@vitejs/plugin-react: ^4.7.0 => 4.7.0
@vitejs/plugin-react-swc: ^3.11.0 => 3.11.0
@vitest/browser: 3.2.4 => 3.2.4
@vitest/ui: 3.2.4 => 3.2.4
playwright: 1.54.2 => 1.54.2
vite: 7.0.6 => 7.0.6
vitest: 3.2.4 => 3.2.4
vitest-browser-react: 1.0.1 => 1.0.1Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status