The issue involves a specific error when testing nested data structures with Immer in Svelte.
The issue occurs when testing nested data structures passed as props in Svelte with Immer, resulting in a `state_descriptors_fixed` error. The problem is reproducible in a test environment but not in the browser. The issue requires understanding both Svelte's state management and Immer's integration.
state_descriptors_fixed error updating nested data passed as props from test in conjunction with immer
Reproduction repo link The repository includes a the immer library to make it easier to work with immutable data. The tests demonstrate the issue when passing a nested data structure to a Page component, and then attempting to update it using a callback method that's activated by a button in the component.
There are two tests in the repo:
The second one passes. Both buttons cause no issues when I test them manually in my browser (I am using Vivaldi, which is Chrome based).
If the nested field is removed, I no longer see those errors in the tests.
> [email protected] test
> npm run test:unit -- --run
> [email protected] test:unit
> vitest --run
RUN v3.0.7 /home/alter_kaker/code/test-error
stderr | src/routes/tests/page.svelte.test.ts > immer
Error: Uncaught [Svelte error: state_descriptors_fixed
Property descriptors defined on `$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`.
https://svelte.dev/e/state_descriptors_fixed]
at reportException (/home/alter_kaker/code/test-error/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
at innerInvokeEventListeners (/home/alter_kaker/code/test-error/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:353:9)
at invokeEventListeners (/home/alter_kaker/code/test-error/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3)
at HTMLButtonElementImpl._dispatch (/home/alter_kaker/code/test-error/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9)
at HTMLButtonElementImpl.dispatchEvent (/home/alter_kaker/code/test-error/node_modules/jsdom/lib/jsdom/living/events/E
Claim this issue to let others know you're working on it. You'll earn 15 points when you complete it!