Skip to content

"You must provide a Promise to expect()" inconsistent between resolves and rejects #6643

@0-CAT

Description

@0-CAT

Describe the bug

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'.

This appears to just be an inconsistency between the two, based on the source code:

CleanShot 2024-10-04 at 20 37 27

CleanShot 2024-10-04 at 20 38 09

Seems like the Jest compatibility was not ported to .resolves but only to .rejects—looks like the bug is with that.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-9omsvx?file=test%2Fbasic.test.ts

System Info

System:
    OS: macOS 15.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 98.27 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.0 - ~/.nvm/versions/node/v20.15.0/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.0/bin/npm
    pnpm: 9.6.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Safari: 18.1
  npmPackages:
    @vitest/coverage-v8: ^2.1.1 => 2.1.1
    @vitest/ui: ^2.1.1 => 2.1.1
    vitest: ^2.1.1 => 2.1.1

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions