Skip to content

test_runner: add mockReturnValue and promise helpers - #66631

Open
araujogui wants to merge 1 commit into
nodejs:mainfrom
araujogui:test-runner-mock-return-value
Open

araujogui wants to merge 1 commit into
nodejs:mainfrom
araujogui:test-runner-mock-return-value

Conversation

@araujogui

Copy link
Copy Markdown
Member

Adds mockReturnValue(), mockResolvedValue() and mockRejectedValue() 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'));

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.44%. Comparing base (7514ef8) to head (d659f36).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66631      +/-   ##
==========================================
- Coverage   92.79%   90.44%   -2.35%     
==========================================
  Files         422      791     +369     
  Lines      193669   276619   +82950     
  Branches    29886    53129   +23243     
==========================================
+ Hits       179712   250191   +70479     
- Misses      13630    16825    +3195     
- Partials      327     9603    +9276     
Files with missing lines Coverage Δ
lib/internal/test_runner/mock/mock.js 97.38% <100.00%> (+0.50%) ⬆️

... and 499 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.

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. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants