-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Svelte 5: unit testing of $derived arry fails after testing $derived array length #12708
Comments
Just a quick question, why are you doing: private _derivedCombiArrayLength = $derived(this._derivedCombiArray.length); When instead you can do: expect(obj.derivedCombiArray.length).toEqual(0); I'll take a bigger look into this tomorrow :) |
Ah, yeah, I also noticed, that that works. I was wondering whether that was because property access via a $derived doesn't work in vitest, or whether this is because of svelte 5's reactive array implementation? Maybe vitest switches back to the default array implementation if that .length property is accessed? Thank you very much for looking into this! |
Nice this found a bug in our reactivity logic. Should have a fix up soon :) Update: figured it out, this was a recent regression. |
Describe the bug
Dear svelte 5 team,
I am experiencing an issue with vitest when unit testing a class with $derived fields.
I am using Svelte 5.0.0-next.206 with svelteKit and have modified my
vite.config.ts
to include (hopefully) all necessary configurations:The class which I want to test with vitest contains two $state arrays and one $derived array which is a combination of the other two:
This works perfectly well in the playground.
However, the testing behaves weirdly. When I test the $derived length of the combined array, the $derived combined array doesn't update anymore:
Am I missing something or is this actually a bug?
Thank you very much for your time and work!
Reproduction
see this Stackblitz
Logs
No response
System Info
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 18.20.3 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 10.2.3 - /usr/local/bin/npm pnpm: 8.15.6 - /usr/local/bin/pnpm npmPackages: svelte: ^5.0.0-next.206 => 5.0.0-next.206
Severity
annoyance
The text was updated successfully, but these errors were encountered: