Enzyme: Full tree rendering without a DOM

Created on 11 Mar 2016  路  4Comments  路  Source: enzymejs/enzyme

We could implement a renderer that was like shallow in terms of lifecycle, and never actually attached to the DOM, but unlike shallow - rendered all the way down to leaf nodes:

function B(props) {
  return (
    <div className="b">
      <div>B</div>
      {props.children}
    </div>
  );
}
function A(props) {
  return (
    <B>
      <div>A</div>
      {this.props.children}
    </B>
  );
}
const wrapper = renderFull(<A>Root</A>);
wrapper.debug();

would output:

<A>
  <B>
    <div className="b">
      <div>B</div>
      <div>A</div>
      Root
    </div>
  </B>
</A>

(with a better name than renderFull of course)

enhancement feature request

Most helpful comment

@sjdemartini one big "advantage" over mount is that this function wouldn't require a document to be present.

All 4 comments

Would this method call the componentWillMount and componentDidMount lifecycle methods?

Interesting concept. What would be the primary differences between this and a mount? When would we prefer this over a mount?

I suppose the main advantage would be that some components rendered in the tree may have behavior in componentDidMount that we don't want to execute or test (like DOM dependencies)?

@sjdemartini one big "advantage" over mount is that this function wouldn't require a document to be present.

Was this page helpful?
0 / 5 - 0 ratings