Skip to content

docs: add example for mocking functions that throw#62152

Open
KJyang-0114 wants to merge 2 commits intonodejs:mainfrom
KJyang-0114:fix/issue-52357-mock-error-throws
Open

docs: add example for mocking functions that throw#62152
KJyang-0114 wants to merge 2 commits intonodejs:mainfrom
KJyang-0114:fix/issue-52357-mock-error-throws

Conversation

@KJyang-0114
Copy link

Add documentation explaining how to mock functions that throw errors and validate them using assert.throws(). Includes examples showing how mock tracks both successful calls and thrown errors.

Refs: #52357

When coverage threshold is not met, the dot reporter now outputs
the error message so users can understand why tests failed.

Refs: nodejs#60884
Add documentation explaining how to mock functions that throw errors
and validate them using assert.throws(). Includes examples showing
how mock tracks both successful calls and thrown errors.

PR-URL: nodejs#52358
Refs: nodejs#52357
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@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 Mar 8, 2026
Copy link
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

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

This is already covered between the assert.throw() and mock.fn() docs, plus there are unrelated changes to implementation files.

But also, usage examples are better in a Learn article.

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