Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Question about enzyme/mocha tests #65

Description

@hstoebel

I'm a little confused on how to write enzyme tests for a component that uses react-dimensions

The component looks like this:

const Show = React.createClass({

  // shortened for brevity.

  render () {
    var width = 0.4 * this.props.containerWidth,
      height = width,
      radius = 0.5 * width
    return (
      <div>
        <h1>{this.state.poll.name}</h1>
        <div className="container-fluid">
          // lots more stuff removed for brevity
        </div>
      </div>
    )
  }
})

export default Dimensions()(Show)

I'm trying to test it like this:

it("contains an h1 as first child", (done) => {
  const wrapper = mount(<Show />);
  expect(wrapper.find('h1')).to.have.length(1);
  done()
});

The above test fails with AssertionError: expected { Object (component, root, ...) } to have a length of 1 but got 0

I looked at the value of wrapper.html() and get <div style="width: 100%; height: 100%; padding: 0px; border: 0px;">0</div>. I believe this touches on #28, but as things work just fine in my browser I'm confused as to why it does not behave as I would expect in my tests. Any ideas? Is there any other code I can provide that would shed light on this situation? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions