-
-
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.
- Loading branch information
1 parent
2db7c67
commit a089c9f
Showing
16 changed files
with
353 additions
and
48 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,55 @@ | ||
# `.setContext(context) => Self` | ||
|
||
A method that sets the context of the root component, and re-renders. Useful for when you are | ||
wanting to test how the component behaves over time with changing contexts. | ||
|
||
NOTE: can only be called on a wrapper instance that is also the root instance. | ||
|
||
|
||
#### Arguments | ||
|
||
1. `context` (`Object`): An object containing new props to merge in with the current state | ||
|
||
|
||
|
||
#### Returns | ||
|
||
`ReactWrapper`: Returns itself. | ||
|
||
|
||
|
||
#### Example | ||
|
||
```jsx | ||
const SimpleComponent = React.createClass({ | ||
contextTypes: { | ||
name: React.PropTypes.string, | ||
}, | ||
render() { | ||
return <div>{this.context.name}</div>; | ||
}, | ||
}); | ||
``` | ||
```jsx | ||
const context = { name: 'foo' }; | ||
const wrapper = mount(<SimpleComponent />, { context }); | ||
expect(wrapper.text()).to.equal('foo'); | ||
wrapper.setContext({ name: 'bar' }); | ||
expect(wrapper.text()).to.equal('bar'); | ||
wrapper.setContext({ name: 'baz' }); | ||
expect(wrapper.text()).to.equal('baz'); | ||
``` | ||
|
||
#### Common Gotchas | ||
|
||
- `.setContext()` can only be used on a wrapper that was initially created with a call to `mount()` | ||
that includes a `context` specified in the options argument. | ||
- The root component you are rendering must have a `contextTypes` static property. | ||
|
||
|
||
#### Related Methods | ||
|
||
- [`.setState(state) => Self`](setState.md) | ||
- [`.setProps(props) => Self`](setProps.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
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,55 @@ | ||
# `.setContext(context) => Self` | ||
|
||
A method that sets the context of the root component, and re-renders. Useful for when you are | ||
wanting to test how the component behaves over time with changing contexts. | ||
|
||
NOTE: can only be called on a wrapper instance that is also the root instance. | ||
|
||
|
||
#### Arguments | ||
|
||
1. `context` (`Object`): An object containing new props to merge in with the current state | ||
|
||
|
||
|
||
#### Returns | ||
|
||
`ShallowWrapper`: Returns itself. | ||
|
||
|
||
|
||
#### Example | ||
|
||
```jsx | ||
const SimpleComponent = React.createClass({ | ||
contextTypes: { | ||
name: React.PropTypes.string, | ||
}, | ||
render() { | ||
return <div>{this.context.name}</div>; | ||
}, | ||
}); | ||
``` | ||
```jsx | ||
const context = { name: 'foo' }; | ||
const wrapper = shallow(<SimpleComponent />, { context }); | ||
expect(wrapper.text()).to.equal('foo'); | ||
wrapper.setContext({ name: 'bar' }); | ||
expect(wrapper.text()).to.equal('bar'); | ||
wrapper.setContext({ name: 'baz' }); | ||
expect(wrapper.text()).to.equal('baz'); | ||
``` | ||
|
||
#### Common Gotchas | ||
|
||
- `.setContext()` can only be used on a wrapper that was initially created with a call to `mount()` | ||
that includes a `context` specified in the options argument. | ||
- The root component you are rendering must have a `contextTypes` static property. | ||
|
||
|
||
#### Related Methods | ||
|
||
- [`.setState(state) => Self`](setState.md) | ||
- [`.setProps(props) => Self`](setProps.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
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
Oops, something went wrong.