Skip to content

test_runner: add mock return, resolve, reject and throw shorthands - #66631

Open
araujogui wants to merge 2 commits into
nodejs:mainfrom
araujogui:test-runner-mock-return-value
Open

araujogui wants to merge 2 commits into
nodejs:mainfrom
araujogui:test-runner-mock-return-value

Conversation

@araujogui

@araujogui araujogui commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Adds mockReturnValue(), mockResolvedValue(), mockRejectedValue() and mockThrownValue() to MockFunctionContext as shorthands for common mockImplementation() patterns, matching the equivalent Jest/Vitest APIs.

fn.mock.mockReturnValue(42);
fn.mock.mockResolvedValue(42);
fn.mock.mockRejectedValue(new Error('boom'));
fn.mock.mockThrownValue(new Error('boom'));

Add mockReturnValue(), mockResolvedValue() and mockRejectedValue()
to MockFunctionContext as shorthands for common mockImplementation()
patterns.

Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 17:56
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

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.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Oct 9, 2026
@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.49%. Comparing base (7514ef8) to head (7460a66).
⚠️ Report is 60 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66631      +/-   ##
==========================================
- Coverage   92.79%   90.49%   -2.30%     
==========================================
  Files         422      791     +369     
  Lines      193669   277122   +83453     
  Branches    29886    53285   +23399     
==========================================
+ Hits       179712   250783   +71071     
- Misses      13630    16752    +3122     
- Partials      327     9587    +9260     
Files with missing lines Coverage Δ
lib/internal/test_runner/mock/mock.js 97.40% <100.00%> (+0.52%) ⬆️

... and 513 files 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.

Comment thread lib/internal/test_runner/mock/mock.js
Add mockThrownValue() to MockFunctionContext as a shorthand for a
mockImplementation() that throws.

Assisted-by: Claude Opus 5.5
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
@araujogui araujogui changed the title test_runner: add mockReturnValue and promise helpers test_runner: add mock return, resolve, reject and throw shorthands Oct 12, 2026
@atlowChemi atlowChemi added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 12, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 12, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@richardlau richardlau added the semver-minor PRs that contain new features and should be released in the next minor version. label Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants