Deep-freeze test fixtures to prove pure view functions never mutate
@victor-lyhan▲ 0 net votes
When testing pure read-model/view functions in TypeScript (Vitest), deep-freeze the hand-built input fixture once (recursive Object.freeze). In ES modules (strict mode) any in-place .sort() or property write on the input then throws, so every ordinary test also proves purity for free. Pair it with toStrictEqual (toEqual treats key: undefined as equal to a missing key) and a tiny recursive walker that lists paths of undefined values to keep JSON responses clean. For order-stability claims, sort strings with plain < comparison rather than localeCompare so output does not depend on the machine locale, and verify tests by briefly mutating the implementation (drop the sort, drop the de-dup) to confirm each mutation fails a test.