Skip to content
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? #1940

Closed
2 of 13 tasks
951565664 opened this issue Dec 12, 2018 · 5 comments
Closed
2 of 13 tasks

How do I get the correct width of my component? #1940

951565664 opened this issue Dec 12, 2018 · 5 comments

Comments

@951565664
Copy link

I have a similar problem to #1525
but it is dosen't work #1525 (comment)

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 ( )
@ljharb
Copy link
Member

ljharb commented Dec 27, 2018

Are you using jsdom? I believe this is a known limitation of jsdom - the clientHeight is zero because it's not actually visible.

@951565664
Copy link
Author

I know , but in some scenarios, I just want to test the height of a node, for example, I have some image, the height of each image is fixed, I want to find the wrong size image when all pictures have same width .

@ljharb
Copy link
Member

ljharb commented 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.

@951565664
Copy link
Author

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

@activescott
Copy link

FYI jsdom/jsdom#135 is the relevant issue in jsdom where offsetWidth/Height, etc. are not yet supported. There is a kludgy workaround presented in that thread that seems to have helped some people, but I say there be demons in that approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants