-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
How do I get the correct width of my component? #1525
Comments
I have pretty similar problem with a pretty simple component. |
Could you create a repository to reproduce this? |
@koba04 I set the width of the react table and its direct parent to 100% and set the width of the root div to 1024px, |
@koba04 just check console log for this kind of snippet:
|
This issue might not be relevant to enzyme because the following script also prints document.body.innerHTML = '<div id="hoge">foo</div>';
console.log(document.querySelector('#hoge').clientHeight); |
@koba04 how did you test it? |
@mklimek I tested it on https://github.com/hex-fire/Sample-1525.git ,which is based on Jest(jsdom). |
I wouldn't be surprised if jsdom is not capable to measure its content by design. |
@mklimek I got it. It means that the component isn't attached a DOM tree so the height is always https://github.com/airbnb/enzyme/blob/master/docs/api/ReactWrapper/detach.md When you use |
@koba04 it works with
Thanks for your help! |
This seems answered. |
@mklimek |
I have a similar issue.
Both
|
I have a similar issue. it dosen't work #1940 |
does |
No, |
I have a customized component which encapsulates a react-table in it. And I want to unit-test this component.
I use jsdom to generate the window and document. Then I use mount to begin with the unit test.
In my component, there is a function to set all the columns' width calculated based on the react-table's width.
I found several things weird:
Current behavior
The react-table's width is 0.
Expected behavior
The react-table's width should be the same as the container's width.
Your environment
API
Version
"enzyme": "^3.2.0",
"jsdom": "^11.5.1",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-table": "^6.5.1",
Adapter
below are the snippets of my code:
code in the setup file for jest:
const jsdom = new JSDOM('<!doctype html><html><body></body></html>', { pretendToBeVisual: true });const { window } = jsdom;
code in the spec file:
const wrapper = mount( <DataViewTable data={global.productsList} idKey="uuid" initSelectedItems={[]} onSelectChange={mockProps.onSelectChange} onRowClicked={(info) => { mockProps.onRowClicked(info); }} initialSort={[{ id: 'lastEdit', desc: true }]} columns={mockColumns} getComponentDOM={mockProps.getTableDOM} noDataText={'mock no data text'} sortByColumn={(id, desc) => { mockProps.sortByColumn(id, desc); }} />);
The text was updated successfully, but these errors were encountered: