`closest` return a wrapper with `length: 1` even with unmatched `selector`
See original GitHub issueconst wrapper = shallow(
React.createElement('div', { className: 'foo' },
React.createElement('div', { className: 'bar' })
)
);
console.log(
wrapper.find('.bar').closest('.fooooo')
);
{
root:
ShallowWrapper {
root: [Circular],
unrendered:
{ '$$typeof': Symbol(react.element),
type: 'div',
key: null,
ref: null,
props: [Object],
_owner: null,
_store: {} },
renderer:
{ _instance: null,
render: [Function: render],
getRenderOutput: [Function: getRenderOutput] },
node:
{ '$$typeof': Symbol(react.element),
type: 'div',
key: null,
ref: null,
props: [Object],
_owner: null,
_store: {} },
nodes: [ [Object] ],
length: 1,
options: {} },
unrendered: null,
renderer: null,
node: undefined,
nodes: [ undefined ],
length: 1,
options: {} }
Dummy ShallowWrapper
is ok, but length
should be 0
.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
Why is my JQuery selector returning a n.fn.init[0], and what is it?
I want to select them by data-id. Now, using JQuery, I know I can select the relevant checkboxes like this: $(".checkbox-wrapper>input[data ...
Read more >can't find() element but wrapper.contains() it #1952 - GitHub
Current behavior I cannot find(Component|".selector") but I can see it via ... not present length... expected 1 but received 0") // wrapper.
Read more >Common mistakes with React Testing Library - Kent C. Dodds
The name wrapper is old cruft from enzyme and we don't need that here. The return value from render is not "wrapping" anything....
Read more >Searching: getElement*, querySelector*
The method elem. closest(css) looks for the nearest ancestor that matches the CSS-selector. The elem itself is also included in the search. In ......
Read more >Querying | Cypress examples (v8.7.0) - Gleb Bahmutov
cy.get uses jQuery selectors , thus you can immediately use them to find elements ... it will still be the original parent DOM...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m seeing this as well.
Finding this too. A workaround to make sure it’s a true match:
wrapper.closest('.fooooooo').is('.fooooooo'); // false