-
-
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.
[New] shallow/mount: Add
.slice()
method
- Loading branch information
Showing
9 changed files
with
220 additions
and
0 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,44 @@ | ||
# `.slice([begin[, end]]) => ReactWrapper` | ||
|
||
Returns a new wrapper with a subset of the nodes of the original wrapper, according to the rules of `Array#slice`. | ||
|
||
|
||
#### Arguments | ||
|
||
1. `begin` (`Number` [optional]): Index from which to slice (defaults to `0`). If negative, this is treated as `length+begin`. | ||
1. `end` (`Number` [optional]): Index at which to end slicing (defaults to `length`). If negative, this is treated as `length+end`. | ||
|
||
|
||
|
||
#### Returns | ||
|
||
`ReactWrapper`: A new wrapper with the subset of nodes specified. | ||
|
||
|
||
|
||
#### Examples | ||
|
||
```jsx | ||
const wrapper = mount( | ||
<div> | ||
<div className="foo bax" /> | ||
<div className="foo bar" /> | ||
<div className="foo baz" /> | ||
</div> | ||
); | ||
expect(wrapper.find('.foo').slice(1)).to.have.length(2); | ||
expect(wrapper.find('.foo').slice(1).at(0).hasClass('bar')).to.equal(true); | ||
expect(wrapper.find('.foo').slice(1).at(1).hasClass('baz')).to.equal(true); | ||
``` | ||
|
||
```jsx | ||
const wrapper = mount( | ||
<div> | ||
<div className="foo bax" /> | ||
<div className="foo bar" /> | ||
<div className="foo baz" /> | ||
</div> | ||
); | ||
expect(wrapper.find('.foo').slice(1, 2)).to.have.length(1); | ||
expect(wrapper.find('.foo').slice(1, 2).at(0).hasClass('bar')).to.equal(true); | ||
``` |
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,44 @@ | ||
# `.slice([begin[, end]]) => ShallowWrapper` | ||
|
||
Returns a new wrapper with a subset of the nodes of the original wrapper, according to the rules of `Array#slice`. | ||
|
||
|
||
#### Arguments | ||
|
||
1. `begin` (`Number` [optional]): Index from which to slice (defaults to `0`). If negative, this is treated as `length+begin`. | ||
1. `end` (`Number` [optional]): Index at which to end slicing (defaults to `length`). If negative, this is treated as `length+end`. | ||
|
||
|
||
|
||
#### Returns | ||
|
||
`ShallowWrapper`: A new wrapper with the subset of nodes specified. | ||
|
||
|
||
|
||
#### Examples | ||
|
||
```jsx | ||
const wrapper = shallow( | ||
<div> | ||
<div className="foo bax" /> | ||
<div className="foo bar" /> | ||
<div className="foo baz" /> | ||
</div> | ||
); | ||
expect(wrapper.find('.foo').slice(1)).to.have.length(2); | ||
expect(wrapper.find('.foo').slice(1).at(0).hasClass('bar')).to.equal(true); | ||
expect(wrapper.find('.foo').slice(1).at(1).hasClass('baz')).to.equal(true); | ||
``` | ||
|
||
```jsx | ||
const wrapper = shallow( | ||
<div> | ||
<div className="foo bax" /> | ||
<div className="foo bar" /> | ||
<div className="foo baz" /> | ||
</div> | ||
); | ||
expect(wrapper.find('.foo').slice(1, 2)).to.have.length(1); | ||
expect(wrapper.find('.foo').slice(1, 2).at(0).hasClass('bar')).to.equal(true); | ||
``` |
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
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