vitest-dev / vitest-dev/vitest

Is it possible to add snapshots in type testing?

Open
#5,857 12 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p2-to-be-discussed
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Clear and concise description of the problem

Here's my scenario:

  • Developing components in a component library
  • Some of the prop signatures for the more complicated components are getting huge as they union with other prop types
  • We want an easy to parse and visually identifiable way of tracking those prop signatures and see what may have changed in a PR
Suggested solution

So I was thinking, some type of type signature snapshot. Similar to the normal .toMatchSnapshot (or inline), but essentially we could pass in MyComponentProps and get out the whole:

type MyComponentProps = {
  variant: 'A' | 'B' | 'C';
  label: string;
  someOtherProp: any;
/// ...etc
}

It's essentially what IDE's are doing on hover when I want to inspect a type signature, but we inject it as a string snapshot for tracking and validating against unwanted changes.

Alternative

Open to any and all suggestions on how this might be possible. I have not found the right set of words to put in to google to find something that does this exact thing.

Additional context

No response

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source files or tests are named. Start by examining the existing .toMatchSnapshot behavior and how Vitest handles TypeScript type information, then determine whether a type signature can be captured as a snapshot. Done would mean a documented, testable way to snapshot a type such as MyComponentProps and detect changes in its rendered signature.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.