Skip to content

Add assert.rejects() and assert.doesNotReject() - #359

Merged
nev21 merged 2 commits into
mainfrom
copilot/add-assert-rejects-doesnotreject
Oct 27, 2026
Merged

nev21 merged 2 commits into
mainfrom
copilot/add-assert-rejects-doesnotreject

Conversation

Copilot AI commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Tripwire's assert API had no equivalent of Node's assert.rejects() and assert.doesNotReject(), so migrating users had to wrap await in try/catch. This adds both functions.

await assert.rejects(fetchUser("missing"), /not found/);
await assert.rejects(async () => { throw new TypeError("bad"); }, TypeError);
await assert.doesNotReject(async () => 42);
  • Implementation (core/src/assert/funcs/rejects.ts)
    • Accepts a promise or a function returning one. Anything else fails fatally.
    • Returns a promise that must be awaited. Assertion failures surface as rejections of that promise.
    • A synchronous throw from the function rejects the returned promise with the original error, as in Node.
    • A rejection reason is checked by delegating to throwsFunc, so the criteria (constructor, instance, string or RegExp, plus msgMatch) match throws.
    • doesNotReject is createNotAdapter(rejectsFunc), mirroring doesNotThrow.
    • Because the check delegates to throws, mismatch failures read "expected … to throw …" rather than "reject". I kept that to avoid duplicating the matching logic. The messages could be reworded if you prefer.
  • Registration and types
    • Both are registered in assertClass.ts with nArgs: 3.
    • IAssertClass.ts has the typings and TypeDoc. They are marked @since 0.2.0 and typed as PromiseLike<AssertInst>.
  • Tests: assert.rejects.test.ts covers resolve and reject paths, criteria mismatch, a synchronous throw, a non-promise input, and negation.
  • Docs
    • migrating-from-node-assert.md: the two functions move from "not available" to the supported mapping table, and the workaround snippet is replaced.
    • docs/README.md: the function list and the migration diff are updated.
    • CHANGELIST.md: new entry under v0.2.0.
    • migrating-from-jest.md is unchanged. Its Jest .rejects matcher row is about the expect side, which this PR does not add.

Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Copilot AI changed the title [WIP] Add assert.rejects() and assert.doesNotReject() functions Add assert.rejects() and assert.doesNotReject() Oct 27, 2026
Copilot AI requested a review from nev21 October 27, 2026 04:48
@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.03%. Comparing base (bcdd464) to head (03fb7d7).

Files with missing lines Patch % Lines
core/src/assert/funcs/rejects.ts 95.45% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #359      +/-   ##
==========================================
- Coverage   97.05%   97.03%   -0.02%     
==========================================
  Files         323      324       +1     
  Lines       16848    16893      +45     
  Branches     4595     4525      -70     
==========================================
+ Hits        16351    16392      +41     
- Misses        497      501       +4     
Files with missing lines Coverage Δ
core/src/assert/assertClass.ts 98.13% <100.00%> (+<0.01%) ⬆️
core/src/assert/interface/IAssertClass.ts 100.00% <ø> (ø)
core/src/assert/funcs/rejects.ts 95.45% <95.45%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nev21
nev21 marked this pull request as ready for review October 27, 2026 05:37
@nev21
nev21 requested review from a team as code owners October 27, 2026 05:37
Copilot AI balanced review requested due to automatic review settings October 27, 2026 05:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 insufficient remaining quota.

@nev21
nev21 enabled auto-merge (squash) October 27, 2026 05:37

@nev21 nev21 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@nevware21-bot nevware21-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved by nevware21-bot

@nev21
nev21 merged commit 2b23ef2 into main Oct 27, 2026
11 checks passed
@nev21
nev21 deleted the copilot/add-assert-rejects-doesnotreject branch October 27, 2026 05:40
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.

[Feature Request] Implement assert.rejects() and assert.doesNotReject()

4 participants