Vue 3 Snapshot Serializer is a library designed to enhance snapshot testing for Vue 3 components within Vitest and Jest environments. It is currently at version 2.13.2 and actively maintained, with frequent minor releases incorporating bug fixes and new features. The library focuses on providing cleaner, more readable snapshots by intelligently handling Vue-specific elements like scoped styles, dynamic attributes, and prop serialization. A key differentiator is its explicit support for both `@vue/test-utils` and `@testing-library/vue`, offering flexible testing approaches. It directly addresses common snapshot noise, making tests more robust and less prone to irrelevant failures. This package is exclusively for Vue 3 projects, with a separate serializer available for Vue 2.
npm install vue3-snapshot-serializerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `vue3-snapshot-serializer` with Vitest, configure global snapshot settings to clean up output, and perform a basic component snapshot test.
Review and update your snapshots (`vitest --updateSnapshot` or `jest --updateSnapshot`). If you prefer the old behavior for specific attributes, configure `global.vueSnapshots.attributesNotToStringify` explicitly in your setup file.
Update your snapshots. If you specifically need the object representation in your snapshots, set `global.vueSnapshots.attributesNotToStringify = [];` in your test setup file.
For Vue 2 projects, use `jest-serializer-vue-tjw` (or similar Vue 2-compatible serializers) instead.
If you encounter TypeScript errors related to `vue3-snapshot-serializer` after upgrading, report the issue to the maintainer. A temporary workaround might involve explicitly casting types or adjusting your `tsconfig.json`.
Understand the documentation for these advanced features before enabling them. Debug snapshot changes by toggling these settings or inspecting the differences carefully.
Review the diff in your test runner output. If the change is intended, update your snapshots by running your test command with the `--updateSnapshot` flag (e.g., `vitest --updateSnapshot` or `jest --updateSnapshot`).
Ensure your `vitest.config.js` or `jest.config.js` correctly points to a setup file, and that setup file contains `expect.addSnapshotSerializer(vue3SnapshotSerializer);` before any tests run. For Vitest, this is typically `setupFiles: ['./vitest.setup.ts']`.
When specifying the serializer path in your `jest.config.js` or `vitest.config.js`, ensure you point to the correct module type based on your test runner's configuration: `./node_modules/vue3-snapshot-serializer/index.js` for CommonJS or `./node_modules/vue3-snapshot-serializer/index.mjs` for ESM. For `expect.addSnapshotSerializer`, use `require('vue3-snapshot-serializer')` for CJS or `import * as serializer from 'vue3-snapshot-serializer'` for ESM.No dependency data recorded yet.