-
-
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.
Add matchesElement on the ReactWrapper
- Loading branch information
1 parent
5b8688a
commit 102d631
Showing
5 changed files
with
133 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# `.matchesElement(node) => Boolean` | ||
|
||
Returns whether or not a given react element matches the current render tree. | ||
It will determine if the the wrapper root node __looks like__ the expected element by checking if all props of the expected element are present on the wrapper root node and equals to each other. | ||
|
||
|
||
#### Arguments | ||
|
||
1. `node` (`ReactElement`): The node whose presence you are detecting in the current instance's | ||
render tree. | ||
|
||
|
||
|
||
#### Returns | ||
|
||
`Boolean`: whether or not the current wrapper match the one passed in. | ||
|
||
|
||
|
||
#### Example | ||
|
||
|
||
```jsx | ||
onst MyComponent = React.createClass({ | ||
handleClick() { | ||
... | ||
}, | ||
render() { | ||
return ( | ||
<div onClick={this.handleClick} className="foo bar">Hello</div> | ||
); | ||
} | ||
}); | ||
|
||
const wrapper = mount(<MyComponent />); | ||
expect(wrapper.matchesElement( | ||
<div>Hello</div> | ||
)).to.equal(true); | ||
expect(wrapper.matchesElement( | ||
<div className="foo bar">Hello</div> | ||
)).to.equal(true); | ||
``` | ||
|
||
|
||
#### Common Gotchas | ||
|
||
- `.matchesElement()` expects a ReactElement, not a selector (like many other methods). Make sure that | ||
when you are calling it you are calling it with a ReactElement or a JSX expression. | ||
- Keep in mind that this method determines matching based on the matching of the node's children as | ||
well. |
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
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