Skip to content

fix: wrap filterNode in arrow function to ignore extra callback args#1377

Open
mixelburg wants to merge 1 commit intotesting-library:mainfrom
mixelburg:fix/filter-node-args-mismatch
Open

fix: wrap filterNode in arrow function to ignore extra callback args#1377
mixelburg wants to merge 1 commit intotesting-library:mainfrom
mixelburg:fix/filter-node-args-mismatch

Conversation

@mixelburg
Copy link
Copy Markdown

@mixelburg mixelburg commented May 1, 2026

Fixes #1360

When printing filtered DOM nodes, Array.prototype.filter passes three arguments (element, index, array) to the callback, but filterNode expects only (node: Node). While this works in JS due to ignored extra arguments, wrapping with an explicit arrow function .filter(node => filterNode(node)) ensures only the element is passed, matching the type signature.

.filter(filterNode) passes (element, index, array) to filterNode, but
filterNode expects only (node: Node). Wrapping with an arrow function
ensures only the element is passed, preventing unexpected behavior when
the Array.prototype.filter callback arguments are misinterpreted.

Fixes testing-library#1360
@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented May 1, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ca964b8:

Sandbox Source
react-testing-library-examples Configuration

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.

prettyDOM filterNode argument is called with more args than expected based on type

1 participant