Gets the instance of the component being rendered as the root node passed into shallow().

NOTE: can only be called on a wrapper instance that is also the root instance. With React 16.x, WP Pumice GRANDEXPLORE All Women's Cole Haan Oxford Leather Terrain Stone instance() returns null for stateless React component/stateless functional components. See example:

Returns (React 16.x)

  • ReactComponent: The stateful React component instance.
  • null: If stateless React component was wrapped.

Returns (React 15.x)

  • ReactComponent: The component instance.

Dainty Taylor All Women's Star Converse Chuck Charcoal Ox ApwaXqxqExample

Preconditions

function Stateless() {
  return <div>Statelessdiv>;
}

Oxford Stone WP Cole All Leather Pumice GRANDEXPLORE Haan Terrain Women's class Stateful extends Terrain Leather Haan Oxford Stone Women's All Pumice Cole WP GRANDEXPLORE React.Component {
  render() {
    return <div>Statefuldiv>;
  }
}

BYD Black W Questar Black adidas Women's Coral Haze EBqP6WEvnXReact 16.x

test('shallow wrapper instance should not be null', () => {
  const wrapper = shallow();
  const instance = wrapper.instance();

  expect(instance).not.to.be.instanceOf(Stateless);
});

test('shallow wrapper instance should not be null', () => {
  const wrapper = shallow();
  const instance = wrapper.instance();

  expect(instance).to.be.instanceOf(Stateful);
});

React 15.x

test('shallow wrapper instance should not be null', () => {
  const wrapper = shallow();
  const instance = wrapper.instance();

  expect(instance).to.be.instanceOf(Stateless);
});

test('shallow wrapper instance should not be null', () => {
  const wrapper = shallow();
  const instance = wrapper.instance();

  expect(instance).to.be.instanceOf(Stateful);
});