close
Skip to content

fix(expect)!: fix toThrow("") behavior by reverting #6710#9643

Merged
sheremet-va merged 3 commits intovitest-dev:mainfrom
hi-ogawa:02-12-fix_fix_tothrowerror_behavior_by_reverting_6710
Apr 21, 2026
Merged

fix(expect)!: fix toThrow("") behavior by reverting #6710#9643
sheremet-va merged 3 commits intovitest-dev:mainfrom
hi-ogawa:02-12-fix_fix_tothrowerror_behavior_by_reverting_6710

Conversation

@hi-ogawa
Copy link
Copy Markdown
Collaborator

@hi-ogawa hi-ogawa commented Feb 12, 2026

Description

At that time, I thought this was a bug, but this special case behavior contradicts with doc https://main.vitest.dev/api/expect.html#tothrowerror. This PR essentially reverts #6710 to remove this behavior and follow the doc.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@hi-ogawa hi-ogawa changed the title fix(expect): fix toThrowError("") behavior by reverting #6710 fix(expect): fix toThrow("") behavior by reverting #6710 Feb 18, 2026
@hi-ogawa hi-ogawa marked this pull request as ready for review February 18, 2026 02:11
@sheremet-va
Copy link
Copy Markdown
Member

Isn't this a breaking change now?

@hi-ogawa
Copy link
Copy Markdown
Collaborator Author

I think so.

@sheremet-va
Copy link
Copy Markdown
Member

As a note, jest also passes:

expect(() => {
  throw new Error('error')
}).toThrow('')

@sheremet-va sheremet-va added this to the 5.0.0 milestone Feb 19, 2026
@sheremet-va sheremet-va changed the title fix(expect): fix toThrow("") behavior by reverting #6710 fix(expect)!: fix toThrow("") behavior by reverting #6710 Mar 5, 2026
@sheremet-va sheremet-va merged commit 6c3e4bd into vitest-dev:main Apr 21, 2026
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants