testing-library / testing-library/dom-testing-library
prettyDOM filterNode argument is called with more args than expected based on type
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3.3k
- Forks
- 474
- PR merge metrics
- No merged PRs in 30d
Description
Relevant code or config:
prettyDOM(container, undefined, {
filterNode: (node, unexpectedArg1, unexpectedArg2, shouldBeUndefined) => {
console.log("arg 1: node - ", node);
console.log("arg 2: unexpected - ", unexpectedArg1);
console.log("arg 3: unexpected - ", unexpectedArg2);
console.log("arg 4: undefined (none) - ", shouldBeUndefined);
debugger;
return true;
},
})
What you did / what happened
The filterNode arg in prettyDOM is typed as having one argument:
filterNode?: (node: Node) => boolean
so I was expecting it to be called with one argument, but it was called with three.
Reproduction:
See in the console that there are three args passed to filterNode:
Problem description:
I think it's being called with three arguments because filterNode is being passed into filter and filter has three args: element, index, and array.
Suggested solution:
Can either the typing of filterNode be updated to indicate that it is called with three arguments or the usage be updated to only call it with the one expected node argument?
Thank you!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/DOMElementFilter.ts at the filterNode usage and compare it with the one-argument declaration in types/pretty-dom.d.ts. Check the Array.filter callback behavior and the linked reproduction, then verify that the runtime call and public type agree on the arguments passed to filterNode.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100