vitest-dev / vitest-dev/vitest
Abbreviate long values in `toBeOneOf` failure messages
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
In PR 8906 I added support for sets to toBeOneOf. If there is a test failure it prints the entire set or array in the console. Which is fine for short sets/arrays but in our case this makes the test results unreadable.
Suggested solution
I suggest to implement a limit for the number of elements that will be printed so it maybe looks something like this:
Set {
"value1",
"value2",
… 420 more items
}
Alternative
The question is whether to implement this just for toBeOneOf or "fix" printExpected and printReceived in general.
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 requests 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
Start at the toBeOneOf failure-message handling and inspect the printExpected and printReceived paths mentioned in the issue. Reproduce a failure with a long Set or array, then verify that output is abbreviated with a count of omitted items while short collections remain readable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100