-
-
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 contains* functions to the ReactWrapper
- Loading branch information
1 parent
d57cc90
commit 5b8688a
Showing
8 changed files
with
453 additions
and
2 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,45 @@ | ||
# `.containsAllMatchingElements(nodes) => Boolean` | ||
|
||
Returns whether or not one of the given react elements are all matching one element in the render tree. | ||
It will determine if an element in the wrapper __looks like__ one of the expected element by checking if all props of the expected element are present on the wrappers element and equals to each other. | ||
|
||
|
||
#### Arguments | ||
|
||
1. `nodes` (`Array<ReactElement>`): The array of nodes whose presence you are detecting in the current instance's | ||
render tree. | ||
|
||
|
||
|
||
#### Returns | ||
|
||
`Boolean`: whether or not the current wrapper has nodes anywhere in its render tree that looks | ||
like the nodes passed in. | ||
|
||
|
||
|
||
#### Example | ||
|
||
|
||
```jsx | ||
const wrapper = mount( | ||
<div> | ||
<span className="foo">Hello</span> | ||
<div style={{ fontSize: 13 }}>Goodbye</div> | ||
<span>Again</span> | ||
</div> | ||
); | ||
|
||
expect(wrapper.containsAllMatchingElements([ | ||
<span>Hello</span>, | ||
<div>Goodbye</div>, | ||
])).to.equal(true); | ||
``` | ||
|
||
|
||
#### Common Gotchas | ||
|
||
- `.containsAllMatchingElements()` expects an array of ReactElement, not a selector (like many other methods). Make sure that | ||
when you are calling it you are calling it with an array of ReactElement or a JSX expression. | ||
- Keep in mind that this method determines mathcing 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# `.containsAnyMatchingElements(nodes) => Boolean` | ||
|
||
Returns whether or not one of the given react elements is matching on element in the render tree. | ||
It will determine if an element in the wrapper __looks like__ one of the expected element by checking if all props of the expected element are present on the wrappers element and equals to each other. | ||
|
||
|
||
#### Arguments | ||
|
||
1. `nodes` (`Array<ReactElement>`): The array of nodes whose presence you are detecting in the current instance's | ||
render tree. | ||
|
||
|
||
|
||
#### Returns | ||
|
||
`Boolean`: whether or not the current wrapper has a node anywhere in its render tree that looks | ||
like one of the array passed in. | ||
|
||
|
||
|
||
#### Example | ||
|
||
|
||
```jsx | ||
const wrapper = mount( | ||
<div> | ||
<span className="foo">Hello</span> | ||
<div style={{ fontSize: 13 }}>Goodbye</div> | ||
<span>Again</span> | ||
</div> | ||
); | ||
|
||
expect(wrapper.containsAnyMatchingElements([ | ||
<span>Bonjour</span>, | ||
<div>Goodbye</div>, | ||
])).to.equal(true); | ||
``` | ||
|
||
|
||
#### Common Gotchas | ||
|
||
- `.containsAnyMatchingElements()` expects an array of ReactElement, not a selector (like many other methods). Make sure that | ||
when you are calling it you are calling it with an array ReactElement or a JSX expression. | ||
- Keep in mind that this method determines equality based on the equality 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# `.containsMatchingElement(node) => Boolean` | ||
|
||
Returns whether or not a given react element is matching one element in the render tree. | ||
It will determine if an element in the wrapper __looks like__ the expected element by checking if all props of the expected element are present on the wrappers element 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 has a node anywhere in its render tree that looks | ||
like the one passed in. | ||
|
||
|
||
|
||
#### Example | ||
|
||
|
||
```jsx | ||
const MyComponent = React.createClass({ | ||
handleClick() { | ||
... | ||
}, | ||
render() { | ||
return ( | ||
<div> | ||
<div onClick={this.handleClick} className="foo bar">Hello</div> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
const wrapper = mount(<MyComponent />); | ||
expect(wrapper.containsMatchingElement( | ||
<div>Hello</div> | ||
)).to.equal(true); | ||
expect(wrapper.containsMatchingElement( | ||
<div className="foo bar">Hello</div> | ||
)).to.equal(true); | ||
``` | ||
|
||
#### Common Gotchas | ||
|
||
- `.containsMatchingElement()` 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 equality based on the equality 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
Oops, something went wrong.