Skip to content

fix: validate throw matchers for falsy thrown values - #1878

Open
xiehuanyi wants to merge 1 commit into
chaijs:mainfrom
xiehuanyi:fix/falsy-throw-matchers-20261013
Open

xiehuanyi wants to merge 1 commit into
chaijs:mainfrom
xiehuanyi:fix/falsy-throw-matchers-20261013

Conversation

@xiehuanyi

Copy link
Copy Markdown

expect(() => { throw null; }).to.throw(TypeError) currently passes because the constructor/message checks require a truthy thrown value. The same false positive affects undefined, false, 0, NaN, and the empty string. Negated message assertions also miss an empty thrown string.

Use the existing errorWasThrown flag to decide whether to check constraints. Guard nullish values before calling the error helpers, so mismatches produce an AssertionError instead of a property-access TypeError. Add regressions for constructors, error instances, strings/regular expressions, and negated empty-string matches.

Validation:

  • New regressions on the unchanged source: 3 failing tests.
  • npm run build and npm run lint: pass.
  • npm run test-node: 515 passing, coverage check passes.
  • Browser suite: 514 passing in installed Google Chrome, using the project's normal configuration plus a local Playwright executable-path override. The default command could not start because its downloaded Chromium revision is absent.
  • git diff --check: pass.

AI assistance: OpenAI gpt-6.1-sol with xhigh reasoning was used to investigate, implement, and validate this change.

@xiehuanyi
xiehuanyi requested a review from a team as a code owner October 12, 2026 22:58
Copilot AI balanced review requested due to automatic review settings October 12, 2026 22:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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