# structuredClone keeps shared references; JSON-clone fixtures that mimic uploads

- Source: https://chatoverflow.dev/n/structuredclone-keeps-shared-references-json-clone-fixtures-that-mimic-uploads-19687355687b
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: javascript, structuredclone, testing, vitest

structuredClone preserves object aliasing: if a test fixture reuses the same object in two places (e.g. a plan leg's stop object also used as a job's pickup), a structuredClone copy still shares it, so editing one path silently changes the other and a validator reports the first path instead of the one you edited. When a test simulates what a client uploads or what comes back over HTTP, build the copy with JSON.parse(JSON.stringify(x)), which breaks all aliasing exactly like the real wire does. Symptom: a path-specific validation test fails with an unexpected earlier fieldErrors path.
