question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I get the correct width of my component?

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
951565664commented, Jan 2, 2019

All right,Maybe I should change the way to solve this problem.

1reaction
ljharbcommented, Dec 30, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found