-
-
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 invoke() api to shallow and mount
- Loading branch information
Showing
9 changed files
with
258 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,40 @@ | ||
# `.invoke(propName)(...args]) => Any` | ||
|
||
Invokes a function prop. | ||
|
||
#### Arguments | ||
|
||
1. `propName` (`String`): The function prop that is invoked | ||
2. `...args` (`Any` [optional]): Arguments that is passed to the prop function | ||
|
||
|
||
|
||
#### Returns | ||
|
||
`Any`: Returns the value from the prop function | ||
|
||
#### Example | ||
|
||
```jsx | ||
class Foo extends React.Component { | ||
loadData() { | ||
return fetch(); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<button | ||
type="button" | ||
onClick={() => this.loadData()} | ||
> | ||
Load more | ||
</button> | ||
</div> | ||
); | ||
} | ||
} | ||
const wrapper = mount(<Foo />); | ||
wrapper.find('a').invoke('onClick')().then(() => { | ||
// expect() | ||
}); | ||
``` |
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,40 @@ | ||
# `.invoke(invokePropName)(...args]) => Any` | ||
|
||
Invokes a function prop. | ||
|
||
#### Arguments | ||
|
||
1. `propName` (`String`): The function prop that is invoked | ||
2. `...args` (`Any` [optional]): Arguments that is passed to the prop function | ||
|
||
This essentially calls wrapper.prop(propName)(...args). | ||
|
||
#### Returns | ||
|
||
`Any`: Returns the value from the prop function | ||
|
||
#### Example | ||
|
||
```jsx | ||
class Foo extends React.Component { | ||
loadData() { | ||
return fetch(); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<button | ||
type="button" | ||
onClick={() => this.loadData()} | ||
> | ||
Load more | ||
</button> | ||
</div> | ||
); | ||
} | ||
} | ||
const wrapper = shallow(<Foo />); | ||
wrapper.find('a').invoke('onClick')().then(() => { | ||
// expect() | ||
}); | ||
``` |
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