-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(types): add better promise support in expects and matchers #8266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
}) | ||
|
||
expect({ a: 1, b: '2' }).toMatchSchema({ a: '1' }) | ||
await (expect({ a: '1' }).resolves.toMatchSchema({ a: '1' }) satisfies Promise<{ a: string }>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This previously wasn't returning a Promise.
import type { Assertion, ExpectPollOptions } from 'vitest' | ||
|
||
declare module 'vitest' { | ||
interface JestAssertion<T = any> extends TestingLibraryMatchers<void, T> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests seem flakey and out of control of my PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(val).resolves.eq(val)
no longer returns a Promise
Added a test and fixed that! Thanks for catching! There's so many cases 🥲 |
We decided that with the amount of breaking changes in Vitest 4 already, we need to postpone this at least to Vitest 5 because the impact is quite big, but it fixes a niche use case |
Fair enough! feel free to tag me when it's time to revisit |
Description
Resolves #6279
At the moment, when you use
.resolves
or.rejects
the type generics get lost due to the Promisify function.See error
This PR changes the types and allows us to also type-check the resolves and reject matchers as well as properly types custom matchers as promises.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.