-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Effects in unit tests don't run #14239
Comments
use |
Thank you, this is what was missing. Just opened a PR to improve the docs and clarify this for other folks. |
enabling jsdom for all tests is not the right way either. instead you need to split your tests into 2 different configs. not entirely intuitive at first you can do it with vitest workspaces, here is an example that does it in the kit demo app https://github.com/dominikg/vitest-example-svelte5/blob/main/vitest.workspace.ts (note the filename and how it uses defineWorkspace + extends vite.config) |
If this is what's needed, should it be added to sv / svelte-add / docs? |
Describe the bug
It seems that code inside an
$effect.root()
in unit tests doesn't run. I'm following the instructions on the docs to set up vitest and a simple test case, but no matter what I tried, the code inside$effect.root()
doesn't run at all in the test.Depending on how the test is set up (e.g. all the assertions are made in code inside
$effect.root()
, which is also what the example in the docs does), vitest reports the test as successful, but that's because no code ran at all. This is misleading.This issue was also observed by someone else on the discord server, but no resolution was found yet over there.
Reproduction
https://www.sveltelab.dev/dnfqrcdar7xg6qw?files=.%2Fsrc%2Flib%2Feffect_test.svelte.test.ts
Please stop the dev server on sveltelab's console and run the
test:unit
npm script instead.Logs
No response
System Info
System: OS: Linux 6.10 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Container: Yes Shell: 5.9 - /bin/zsh Binaries: Node: 22.8.0 - /nix/store/xsrv93rg8vi05k9ig6v9mcvcyn01n6n2-nodejs-22.8.0/bin/node npm: 10.8.2 - /nix/store/xsrv93rg8vi05k9ig6v9mcvcyn01n6n2-nodejs-22.8.0/bin/npm Browsers: Chromium: 130.0.6723.69 npmPackages: svelte: ^5.1.9 => 5.1.9
Severity
blocking all usage of svelte
The text was updated successfully, but these errors were encountered: