-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getPublicInstance is not a function #4
Comments
This is actually a problem in enzyme, however I've been unable to fix it. I do I have a test that provokes the problem. I'll have a PR up shortly. The problem is in knowing what MountedTraversal:childrenOfInstInternal should return at certain points. // called with a private instance
export function childrenOfInstInternal(inst) {
if (!inst) {
return [];
}
if (!inst.getPublicInstance) {
const internal = internalInstance(inst);
return childrenOfInstInternal(internal);
}
const publicInst = inst.getPublicInstance();
const currentElement = inst._currentElement;
if (isDOMComponent(publicInst)) {
const renderedChildren = renderedChildrenOfInst(inst);
return Object.keys(renderedChildren || {}).filter((key) => {
if (REACT013 && !renderedChildren[key].getPublicInstance) {
return false;
}
return true;
}).map(key => {
if (!REACT013 && typeof renderedChildren[key]._currentElement.type === 'function') {
return renderedChildren[key]._instance;
}
if(renderedChildren[key].getPublicInstance) {
return renderedChildren[key].getPublicInstance();
}
// Here's the problem:
// Neither of these really work
return null; //childrenOfInstInternal(internalInstance(renderedChildren[key]));
});
} else if (
!REACT013 &&
isElement(currentElement) &&
typeof currentElement.type === 'function'
) {
return childrenOfInstInternal(inst._renderedComponent);
} else if (
REACT013 &&
isCompositeComponent(publicInst)
) {
return childrenOfInstInternal(inst._renderedComponent);
}
return [];
} One of the choices truncates the tree, another causes a different fatal error. |
Hi! |
From @mark0978's provided example, this fails: <div>
<div></div>
<div>B<span></span></div>
</div> but this works: <div>
<div></div>
<div>B</div>
</div> It seems like EDIT: Narrowing down the issue, this is enough to reproduce the issue: const mounted = mount(<div>B<span></span></div>);
expect(mountToJson(mounted)).toMatchSnapshot(); Probably because of the text node being next to the |
Actually just running this: mount(<div>B<span></span></div>).children(); provokes the error, and it doesn't involve our library, so that looks like an Enzyme issue. 🤔 |
thanks. do you mind raising an issue there. Hopefully you can explain better on what the desired output, ... thanks again for your quick response. |
Yeah I will raise an issue in Enzyme and look at making this plugin work as closely as possible to |
The issue is being solved on Enzyme side see: enzymejs/enzyme#603 and enzymejs/enzyme#604 |
thanks. I been watching that issue. you guys are awesome :-) |
@adriantoine I patched my enzyme with the changes enzymejs/enzyme#604 and it worked well.
Is there a way to consider only the real dom nodes? thanks. |
Hi @bsr203, Thanks for the suggestions, can you open that in another github issue? I'll close this one when the issue is fixed in Enzyme 😊 |
FYI the exception won't be there in This test: const mounted = mount(<div>B<span></span></div>);
expect(mountToJson(mounted)).toMatchSnapshot(); Gives this snapshot: <div>
<span />
</div> So the |
I don't think this bug occurs anymore, if it does, feel free to leave a comment here! |
Hi,
I have a bit of a complex component, which renders pretty printed message with enzyme
w.debug()
. But, getting following stack when use withmountToJson
can you give some pointers to identify the issue without a test repo :-)
thanks.
bsr.
The text was updated successfully, but these errors were encountered: