-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed typo 'validNumber..' to 'validateNumber...'
- Loading branch information
1 parent
67a1456
commit 3bd7a40
Showing
3 changed files
with
37 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters