Skip to content

Commit

Permalink
[Docs] typo in .prop(key)
Browse files Browse the repository at this point in the history
changed typo 'validNumber..' to 'validateNumber...'
  • Loading branch information
pinkbunny1 authored and ljharb committed Oct 29, 2018
1 parent 67a1456 commit 3bd7a40
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
36 changes: 31 additions & 5 deletions docs/api/ReactWrapper/props.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,47 @@
# `.props() => Object`

Returns the props hash for the current node of the wrapper.
Returns the props hash for the root node of the wrapper.

NOTE: can only be called on a wrapper of a single node.

To return the props for the entire React component, use `wrapper.instance().props`. This is valid for stateful or stateless components in React `15.*`. But, `wrapper.instance()` will return `null` for stateless React component in React `16.*`, so `wrapper.instance().props` will cause an error in this case. See [`.instance() => ReactComponent`](instance.md)


#### Example
```jsx

import PropTypes from 'prop-types';

```jsx
const wrapper = mount(<MyComponent foo={10} />);
expect(wrapper.props().foo).to.equal(10);
function MyComponent(props) {
const { includedProp } = props;
return (
<div className="foo bar" includedProp={includedProp}>Hello</div>
);
}
MyComponent.propTypes = {
includedProp: PropTypes.string.isRequired,
};

const wrapper = mount(<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 root node,
// which does not include excludedProp in this example.
// See the note above about wrapper.instance().props.

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

console.log(wrapper.instance().props); // React 15.x - working as expected
// {children: "Hello", className: "foo bar", includedProp:"Success!", excludedProp: "I'm not included"}

console.log(wrapper.instance().props);
// React 16.* - Uncaught TypeError: Cannot read property 'props' of null
```


#### Related Methods

- [`.prop() => Object`](prop.md)
- [`.prop(key) => Any`](prop.md)
- [`.state([key]) => Any`](state.md)
- [`.context([key]) => Any`](context.md)
4 changes: 2 additions & 2 deletions docs/api/ShallowWrapper/prop.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ const wrapper = shallow(<MyComponent includedProp="Success!" excludedProp="I'm n
expect(wrapper.prop('includedProp')).to.equal('Success!');

const validInput = 1;
wrapper.find('ValidNumberInputComponent').prop('onChangeHandler')(validInput);
wrapper.find('ValidateNumberInputComponent').prop('onChangeHandler')(validInput);
expect(wrapper.state('number')).to.equal(number);

const invalidInput = 'invalid input';
wrapper.find('ValidNumberInputComponent').prop('onChangeHandler')(invalidInput);
wrapper.find('ValidateNumberInputComponent').prop('onChangeHandler')(invalidInput);
expect(wrapper.state('number')).to.equal(0);

// Warning: .prop(key) only returns values for props that exist in the root node.
Expand Down
8 changes: 4 additions & 4 deletions docs/api/ShallowWrapper/props.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# `.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.
Returns the props hash for the root node of the wrapper.

NOTE: When called on a shallow wrapper, `.props()` will return values for
props on the root node that the component *renders*, not the component itself.
NOTE: can only be called on a wrapper of a single node.

NOTE: When called on a shallow wrapper, `.props()` will return values for props on the root node that the component *renders*, not the component itself.

To return the props for the entire React component, use `wrapper.instance().props`. This is valid for stateful or stateless components in React `15.*`. But, `wrapper.instance()` will return `null` for stateless React component in React `16.*`, so `wrapper.instance().props` will cause an error in this case. See [`.instance() => ReactComponent`](instance.md)

Expand Down

0 comments on commit 3bd7a40

Please sign in to comment.