Describe the bug
Mostly a the same as #6643 but now Jest supports functions with resolves: jestjs/jest#15713
If you call await expect(async () => { ... }).rejects.toThrow(), this will work as expected. However, change this to await expect(async () => { ... }).resolves.not.toThrow() and the test fails with the following error:
TypeError: You must provide a Promise to expect() when using .resolves, not 'function'.
|
const obj = utils.flag(this, 'object') |
|
const wrapper = typeof obj === 'function' ? obj() : obj // for jest compat |
|
|
|
if (utils.flag(this, 'poll')) { |
|
throw new SyntaxError( |
|
`expect.poll() is not supported in combination with .rejects`, |
|
) |
|
} |
|
|
|
if (typeof wrapper?.then !== 'function') { |
|
throw new TypeError( |
|
`You must provide a Promise to expect() when using .rejects, not '${typeof wrapper}'.`, |
|
) |
|
} |
|
const obj = utils.flag(this, 'object') |
|
|
|
if (utils.flag(this, 'poll')) { |
|
throw new SyntaxError( |
|
`expect.poll() is not supported in combination with .resolves`, |
|
) |
|
} |
|
|
|
if (typeof obj?.then !== 'function') { |
|
throw new TypeError( |
|
`You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.`, |
|
) |
|
} |
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-9omsvx?file=test%2Fbasic.test.ts
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 22.22.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@vitest/ui: 4.1.5 => 4.1.5
vite: 8.0.10 => 8.0.10
vitest: 4.1.5 => 4.1.5
Used Package Manager
npm
Validations
Describe the bug
Mostly a the same as #6643 but now Jest supports functions with resolves: jestjs/jest#15713
If you call await expect(async () => { ... }).rejects.toThrow(), this will work as expected. However, change this to await expect(async () => { ... }).resolves.not.toThrow() and the test fails with the following error:
TypeError: You must provide a Promise to expect() when using .resolves, not 'function'.
vitest/packages/expect/src/jest-expect.ts
Lines 1149 to 1162 in cba2036
vitest/packages/expect/src/jest-expect.ts
Lines 1077 to 1089 in cba2036
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-9omsvx?file=test%2Fbasic.test.ts
System Info
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 22.22.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 10.8.2 - /usr/local/bin/npm pnpm: 8.15.6 - /usr/local/bin/pnpm npmPackages: @vitest/ui: 4.1.5 => 4.1.5 vite: 8.0.10 => 8.0.10 vitest: 4.1.5 => 4.1.5Used Package Manager
npm
Validations