W3cubDocs

/Enzyme

.dive([options]) => ShallowWrapper

Shallow render the one non-DOM child of the current wrapper, and return a wrapper around the result. It must be a single-node wrapper, and the node must be a React component.

There is no corresponding dive method for ReactWrappers.

NOTE: can only be called on a wrapper of a single non-DOM component element node, otherwise it will throw an error. If you have to shallow-wrap a wrapper with multiple child nodes, use .shallow().

Arguments

  1. options (Object [optional]):
  2. options.context: (Object [optional]): Context to be passed into the component

Returns

ShallowWrapper: A new wrapper that wraps the current node after it's been shallow rendered.

Examples

function Bar() {
  return (
    <div>
      <div className="in-bar" />
    </div>
  );
}
function Foo() {
  return (
    <div>
      <Bar />
    </div>
  );
}
const wrapper = shallow(<Foo />);
expect(wrapper.find('.in-bar')).to.have.lengthOf(0);
expect(wrapper.find(Bar)).to.have.lengthOf(1);
expect(wrapper.find(Bar).dive().find('.in-bar')).to.have.lengthOf(1);

© 2015 Airbnb, Inc.
Licensed under the MIT License.
https://airbnb.io/enzyme/docs/api/ShallowWrapper/dive.html