-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
$effect
not working in tests, but $derived
does
#15051
Comments
$effect
not working in tests$effect
not working in tests, but $derived
does
It means nothing - Did you read the docs about testing? |
Yes, that's what I meant. Isn't it reactive in my example above? |
This could be fixed by #14977 but I think you should change your resolve conditions to |
I don't need that, as I mentioned it is reactive for me.
I tried doing that, but I'm getting blasted with various errors, like
also, this makes every server test to fail. |
Do you have other tests other than those? You need to run the svelte ones with condition browser and the others with condition node...take a look at this repo |
I will take a look at that repo, although not sure if it will help, running just a single file with the test in my original post fails with the errors I mentioned. Also, I managed to get the transformed module, which looks good I think: let num = __vite_ssr_import_0__.state(0);
let doubled = __vite_ssr_import_0__.derived(() => __vite_ssr_import_0__.get(num) * 2);
__vite_ssr_import_0__.set(num, 5);
__vite_ssr_import_1__.expect(__vite_ssr_import_0__.get(doubled)).toBe(10);
__vite_ssr_import_0__.effect_root(() => {
let a = 0;
__vite_ssr_import_0__.user_effect(() => {
a = 5;
});
__vite_ssr_import_3__.flushSync();
__vite_ssr_import_1__.expect(a).toBe(5);
}); Update: actually, I think I figured it out. Looking at the top of the generated module, I see this: const __vite_ssr_import_0__ = await __vite_ssr_import__("/node_modules/svelte/src/internal/client/index.js");
const __vite_ssr_import_1__ = await __vite_ssr_import__("/node_modules/vitest/dist/index.js", {"importedNames":["vi","expect","it","describe"]});
const __vite_ssr_import_3__ = await __vite_ssr_import__("/node_modules/svelte/src/index-server.js", {"importedNames":["flushSync"]}); so, runes are transformed correctly, but |
After upgrading to Vitest 3, I finally managed to get this working, using the example repo from above, with the workspace config. |
Describe the bug
I'm having this weird issue where
$effect
is not working in tests. Interestingly,$derived
does work, which means Svelte is not compiling in SSR mode. For example, in this test:it errors at the very end:
expected +0 to be 5
, but it should work. Here's my Vite config:I also have this mock in my global setup as I use
if (browser)
in other places in my tests:I tried removing it, but without success. I'm not quite sure how to reproduce this yet. Is there something obviously wrong with my config, or something I can try?
The text was updated successfully, but these errors were encountered: