Skip to content

Commit

Permalink
fix(expect): fix expect().resolves/rejects chain typings (#7273)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Jan 17, 2025
1 parent 149380b commit fa41505
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 1 addition & 3 deletions packages/expect/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,7 @@ type VitestAssertion<A, T> = {

type Promisify<O> = {
[K in keyof O]: O[K] extends (...args: infer A) => infer R
? O extends R
? Promisify<O[K]>
: (...args: A) => Promise<R>
? Promisify<O[K]> & ((...args: A) => Promise<R>)
: O[K];
}

Expand Down
13 changes: 13 additions & 0 deletions test/core/test/jest-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,19 @@ describe('async expect', () => {
expect(error).toMatchObject({ message: 'promise rejected "+0" instead of resolving' })
}
})

it('chainable types', async () => {
/* eslint-disable prefer-promise-reject-errors */
await expect(Promise.resolve(1)).resolves.toBeOneOf([1])
await expect(Promise.resolve(1)).resolves.not.toBeOneOf([2])
await expect(Promise.reject(1)).rejects.toBeOneOf([1])
await expect(Promise.reject(1)).rejects.not.toBeOneOf([2])
await expect(Promise.resolve(1)).resolves.toSatisfy(v => v === 1)
await expect(Promise.reject(2)).rejects.toSatisfy(v => v === 2)
await (expect(Promise.resolve(1)).resolves.to.equal(1) satisfies Promise<any>)
await (expect(Promise.resolve(1)).resolves.not.to.equal(2) satisfies Promise<any>)
/* eslint-enable prefer-promise-reject-errors */
})
})

it('compatible with jest', () => {
Expand Down

0 comments on commit fa41505

Please sign in to comment.