diff --git a/packages/expect/src/types.ts b/packages/expect/src/types.ts index 963273382a2a..792a8b84a6e8 100644 --- a/packages/expect/src/types.ts +++ b/packages/expect/src/types.ts @@ -622,9 +622,7 @@ type VitestAssertion = { type Promisify = { [K in keyof O]: O[K] extends (...args: infer A) => infer R - ? O extends R - ? Promisify - : (...args: A) => Promise + ? Promisify & ((...args: A) => Promise) : O[K]; } diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index d1f2a635d3a2..93566aec301b 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -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) + await (expect(Promise.resolve(1)).resolves.not.to.equal(2) satisfies Promise) + /* eslint-enable prefer-promise-reject-errors */ + }) }) it('compatible with jest', () => {