agentsclimarketplace

Managing snapshot tests

Skill jeremylongshore/claude-code-plugins-plus-skills/plugins/testing/snapshot-test-manager/skills/managing-snapshot-tests

425 plugins, 2,810 skills, 200 agents for Claude Code. Open-source marketplace at tonsofskills.com with the ccpi CLI package manager.

Install
npx -y skills add jeremylongshore/claude-code-plugins-plus-skills --skill managing-snapshot-tests

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its author says it does

Copied from the file, not written here

'Create and validate component snapshots for UI regression testing.

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

5.7 KB, as published. Nobody here has run it

Snapshot Test Manager

Overview

Create, update, and maintain snapshot tests for UI components and data structures using Jest, Vitest, or pytest snapshot plugins. Manages serialized output snapshots (HTML, JSON, component trees) to detect unexpected changes in rendered output.

Prerequisites

  • Jest or Vitest with built-in snapshot support, or pytest-snapshot/syrupy for Python
  • React Testing Library, Vue Test Utils, or equivalent for component rendering
  • Snapshot files committed to version control (.snap files or __snapshots__/ directory)
  • Component library with stable prop interfaces
  • Code review process that includes snapshot diff review

Instructions

  1. Identify components and data structures suitable for snapshot testing:
    • UI components with complex rendered output (navigation bars, forms, cards).
    • API response transformers producing structured JSON.
    • Configuration generators outputting YAML or TOML.
    • Avoid snapshots for highly dynamic content (timestamps, random IDs).
  2. Write snapshot tests for each target:
    • Render the component with representative props.
    • Call expect(result).toMatchSnapshot() or toMatchInlineSnapshot().
    • Create separate snapshots for each meaningful prop combination.
    • Use inline snapshots for small outputs (under 20 lines) for better readability.
  3. Organize snapshot files:
    • Group snapshots by component in __snapshots__/ComponentName.test.ts.snap.
    • Name each snapshot descriptively: "renders with error state", "displays loading skeleton".
    • Keep snapshot files in the same directory as the test file.
  4. Review and update snapshots when intentional changes occur:
    • Run jest --updateSnapshot or vitest --update after verifying changes are correct.
    • Review every line of the snapshot diff in pull requests -- do not blindly update.
    • Add a comment in the PR explaining why snapshots changed.
  5. Clean up obsolete snapshots:
    • Run jest --ci to detect obsolete snapshots that no longer match any test.
    • Delete orphaned .snap files for removed components.
    • Periodically run snapshot cleanup to prevent stale data.
  6. Set up CI to fail on snapshot mismatches without auto-updating:
    • Use --ci flag which treats missing snapshots as failures.
    • Upload snapshot diff output as a CI artifact for review.
  7. Consider property-based snapshot alternatives for large components:
    • Use toMatchObject for partial structure matching.
    • Use custom serializers to exclude volatile fields.

Output

  • Snapshot test files (*.test.ts or *.test.tsx) with toMatchSnapshot() assertions
  • Snapshot data files (__snapshots__/*.snap)
  • Snapshot update report listing changed, added, and removed snapshots
  • CI configuration preventing accidental snapshot updates in automated runs
  • Custom serializer modules for filtering dynamic content

Error Handling

ErrorCauseSolution
Snapshot mismatch on unrelated changeComponent depends on a shared style or context providerIsolate components with wrapper providers; mock global styles
Snapshot file is enormous (>1000 lines)Entire page DOM serialized instead of target componentNarrow the snapshot scope to the specific component subtree; use container.querySelector
Obsolete snapshot warningTest was renamed or deleted but .snap file remainsRun jest --updateSnapshot to remove orphaned entries; delete unused .snap files
Snapshot differs between local and CIDifferent Node.js version or OS renders slightly different outputPin Node.js version in CI; use toMatchInlineSnapshot for exact control
Non-deterministic snapshotComponent includes random keys, timestamps, or Math.random()Mock Date.now() and Math.random(); use expect.any(String) for volatile fields

Examples

React component snapshot test (Jest):

import { render } from '@testing-library/react';
import { Alert } from './Alert';

describe('Alert', () => {
  it('renders success variant', () => {
    const { container } = render(
      <Alert variant="success" message="Operation completed" />
    );
    expect(container.firstChild).toMatchSnapshot();
  });

  it('renders error with inline snapshot', () => {
    const { container } = render(
      <Alert variant="error" message="Something failed" />
    );
    expect(container.firstChild).toMatchInlineSnapshot(`
      <div class="alert alert-error" role="alert">
        <span>Something failed</span>
      </div>
    `);
  });
});

Custom serializer to exclude dynamic IDs:

// jest.config.ts
export default {
  snapshotSerializers: ['./test/serializers/strip-ids.ts'],
};

// test/serializers/strip-ids.ts
export const serialize = (val: string) =>
  val.replace(/id="[a-z0-9-]+"/g, 'id="[dynamic]"');
export const test = (val: unknown) => typeof val === 'string' && val.includes('id=');

Resources

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.