How do I get the correct width of my component?
See original GitHub issueI have a similar problem to https://github.com/airbnb/enzyme/issues/1525 but it is dosen’t work https://github.com/airbnb/enzyme/issues/1525#issuecomment-373008462
my code:
describe('test', () => {
it('test', async () => {
document.body.innerHTML = '<div id="test"></div>'
const wrapper1 = mount(<div style={{ height: '10px' }}>0</div>, {
attachTo: document.querySelector('#test')
})
const dom1 = wrapper1.getDOMNode()
//dom1 .clientHeight => 0
})
})
Current behavior
dom1 .clientHeight = 0
Expected behavior
dom1 .clientHeight = 10
Your environment
windows
API
- shallow
- mount
- render
Adapter
- enzyme-adapter-react-16
- enzyme-adapter-react-16.3
- enzyme-adapter-react-16.2
- enzyme-adapter-react-16.1
- enzyme-adapter-react-15
- enzyme-adapter-react-15.4
- enzyme-adapter-react-14
- enzyme-adapter-react-13
- enzyme-adapter-react-helper
- others ( )
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How do I get the correct width of my component? #1525 - GitHub
In my component, there is a function to set all the columns' width calculated based on the react-table's width.
Read more >How to get a react component's size (height/width) before ...
When I'd make a widget in jquery I could just $('#container').width() and get the width of the container ahead of time when I...
Read more >Find the dimensions of a web page element - Boston University
Find the content area and click to focus on it. Back in the bottom window, click Box Model on the right. The width...
Read more >Determining the dimensions of elements - Web APIs | MDN
There are several properties you can look at in order to determine the width and height of elements, and it can be tricky...
Read more >Height and Width - React Native
The general way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in...
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
All right,Maybe I should change the way to solve this problem.
Then it seems like you’d need to test it in an actual browser, and not using jsdom - this doesn’t seem related to enzyme.