vitest-dev / vitest-dev/vitest
Is it possible to add snapshots in type testing?
Nobody has claimed this yet.
- 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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