-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Select component is not rendering children when using enzyme #11074
Comments
Same here. Im trying to read
|
@yoanisgil I fear it's a limitation of enzyme. The Select component portals it's children to the body. I would encourage you to have a look at our tests: |
@oliviertassinari Im using Can you suggest me any workaround. |
@steelx |
@oliviertassinari I was looking at those tests but they are for SelectInput and I'm using Select. I was also looking at this: and initially I would have expected to see a test around making sure that all children are rendered. But maybe is because the issue that we are discussing here? |
@oliviertassinari I think none of the children component gets rendered if we use enzyme. I have observed similar behavior with Dialog. |
I think the issue is that they get rendered but not as children of the Select component so that's why they can't be found. At least that's what I see when I inspect the DOM while my application, that contains a Select, is running. |
@talmukund @yoanisgil What version of enzyme are you using? The portal part was an important pain point when I upgraded from React 15.x to React 16.x. We have removed our "hack" recently as enzyme better support the Portal API. Maybe, it's still in need for you guys: #10208 |
If that works, we can consider adding an option to the portal to disable the behavior for testing purposes. |
Using:
I'm not sure I understand the previous comment :(. |
@oliviertassinari I have also observed issue comes only when component is part of portal. I will check same issue with react 15.x. |
Im not using Portal though Im using React 16.2.0 |
I think that we can move the discussion to enzymejs/enzyme#252. Regarding the workaround. People can follow the old approach we were using https://github.com/mui-org/material-ui/pull/10208/files. It's basically mocking the portal so it renders directly into the DOM. I'm also working on adding a global |
I'm reverting. It was working fine… I have added a test case in #11116. it('should work with a high-level component like the Select', () => {
const wrapper = mount(
<Select value={1} open>
<MenuItem value={1}>
<em>1</em>
</MenuItem>
<MenuItem value={2}>
<em>2</em>
</MenuItem>
</Select>,
);
assert.strictEqual(wrapper.find(MenuItem).length, 2);
}); |
Ok. Let me know once it's merged and I can test ;). |
The Select component is not rendering it's children when using enzyme's mount function.
The following test should pass:
Current Behavior
The test fails with:
Context
The component itself renders like this:
Your Environment
The text was updated successfully, but these errors were encountered: