Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.29 KB

props.md

File metadata and controls

42 lines (29 loc) · 1.29 KB

.props() => Object

Returns the props hash for the root node of the wrapper. .props() can only be called on a wrapper of a single node.

NOTE: When called on a shallow wrapper, .props() will only return the props for the parent element in the component, not the whole React component. To return the props for the entire React component, use wrapper.instance().props. See .instance() => ReactComponent

Example

const MyComponent = React.createClass({
  render() {
    return (
        <div className="foo bar" includedProp={this.props.includedProp}>Hello</div>
    )
  }
})
const wrapper = shallow(<MyComponent includedProp="Success!" excludedProp="I'm not included" />);
expect(wrapper.props().includedProp).to.equal("Success!");

// Warning: .props() only returns props that are passed to the parent element,
// which does not include excludedProp in this example.
// See the note above about wrapper.instance().props.

wrapper.props();
// {children: "Hello", className: "foo bar", includedProp="Success!"}

wrapper.instance().props;
// {children: "Hello", className: "foo bar", includedProp:"Success!", excludedProp: "I'm not included"}

Related Methods