Skip to content

fix(mock): restore single-arg MockCallHistory.filterCallsByX#5328

Open
youcefzemmar wants to merge 1 commit into
nodejs:mainfrom
youcefzemmar:fix/mockagent-mockcallhistory-filtercallsbyx-broken-si
Open

fix(mock): restore single-arg MockCallHistory.filterCallsByX#5328
youcefzemmar wants to merge 1 commit into
nodejs:mainfrom
youcefzemmar:fix/mockagent-mockcallhistory-filtercallsbyx-broken-si

Conversation

@youcefzemmar
Copy link
Copy Markdown

What

Restores the documented mockCallHistory.filterCallsByX(value) single-argument form. The helper returned by makeFilterCalls now defaults logs to this.logs, so external callers work again. Internal callers in filterCalls still pass logs explicitly, so the AND/OR semantics from #5045 are unchanged.

Why

In 8.2.0, the makeFilterCalls helper was refactored to take a second logs argument used by the new AND/OR filter operators. The internal handleFilterCallsWithOptions always passes it, but the public methods (filterCallsByPath, filterCallsByMethod, etc.) are still documented to accept a single argument. Calling any filterCallsByX('value') since 8.2.0 throws Cannot read properties of undefined (reading 'filter').

Testing

  • ran node --test test/mock-call-history.js — 46/46 green (10 new tests in the MockCallHistory - filterCallsByX block exercising each public filter helper plus a regression for "logs added after the method was bound")
  • ran node_modules/.bin/eslint --cache lib/mock/mock-call-history.js test/mock-call-history.js — clean
  • verified the issue's reproducer against the patched build

Notes

The optional second logs parameter on the public methods wasn't documented, so no type-definition change is needed.

Fixes #5324.

The internal `handleFilterCallsWithOptions` refactor in 8.2.0 added a
required `logs` parameter to the helper returned by `makeFilterCalls`,
breaking the documented public API: callers using
`mockCallHistory.filterCallsByPath('/foo')` hit
`Cannot read properties of undefined (reading 'filter')`.

Default `logs` to `this.logs` so the external single-argument form works
again. The internal callers in `filterCalls` still pass an explicit
`logs` argument, so the AND/OR behavior from nodejs#5045 is unaffected.

Fixes nodejs#5324.
@youcefzemmar youcefzemmar marked this pull request as ready for review May 27, 2026 14:10
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.

MockAgent MockCallHistory.filterCallsByX broken since 8.2.0

1 participant