-
-
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 mount() API for wrapping the root in a component
- Loading branch information
1 parent
86f571c
commit 34e2c84
Showing
9 changed files
with
694 additions
and
3 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 @@ | ||
# `.getWrappingComponent() => ReactWrapper` | ||
|
||
If a `wrappingComponent` was passed in `options`, this methods returns a `ReactWrapper` around the rendered `wrappingComponent`. This `ReactWrapper` can be used to update the `wrappingComponent`'s props, state, etc. | ||
|
||
|
||
#### Returns | ||
|
||
`ReactWrapper`: A `ReactWrapper` around the rendered `wrappingComponent` | ||
|
||
|
||
|
||
#### Examples | ||
|
||
```jsx | ||
import { Provider } from 'react-redux'; | ||
import { Router } from 'react-router'; | ||
import store from './my/app/store'; | ||
import mockStore from './my/app/mockStore'; | ||
|
||
function MyProvider(props) { | ||
const { children, customStore } = props; | ||
|
||
return ( | ||
<Provider store={customStore || store}> | ||
<Router> | ||
{children} | ||
</Router> | ||
</Provider> | ||
); | ||
} | ||
MyProvider.propTypes = { | ||
children: PropTypes.node, | ||
customStore: PropTypes.shape({}), | ||
}; | ||
MyProvider.defaultProps = { | ||
children: null, | ||
customStore: null, | ||
}; | ||
|
||
const wrapper = mount(<MyComponent />, { | ||
wrappingComponent: MyProvider, | ||
}); | ||
const provider = wrapper.getWrappingComponent(); | ||
provider.setProps({ customStore: mockStore }); | ||
``` |
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 @@ | ||
# `.getWrappingComponent() => ShallowWrapper` | ||
|
||
If a `wrappingComponent` was passed in `options`, this methods returns a `ShallowWrapper` around the rendered `wrappingComponent`. This `ShallowWrapper` can be used to update the `wrappingComponent`'s props, state, etc. | ||
|
||
|
||
#### Returns | ||
|
||
`ShallowWrapper`: A `ShallowWrapper` around the rendered `wrappingComponent` | ||
|
||
|
||
|
||
#### Examples | ||
|
||
```jsx | ||
import { Provider } from 'react-redux'; | ||
import { Router } from 'react-router'; | ||
import store from './my/app/store'; | ||
import mockStore from './my/app/mockStore'; | ||
|
||
function MyProvider(props) { | ||
const { children, customStore } = props; | ||
|
||
return ( | ||
<Provider store={customStore || store}> | ||
<Router> | ||
{children} | ||
</Router> | ||
</Provider> | ||
); | ||
} | ||
MyProvider.propTypes = { | ||
children: PropTypes.node, | ||
customStore: PropTypes.shape({}), | ||
}; | ||
MyProvider.defaultProps = { | ||
children: null, | ||
customStore: null, | ||
}; | ||
|
||
const wrapper = shallow(<MyComponent />, { | ||
wrappingComponent: MyProvider, | ||
}); | ||
const provider = wrapper.getWrappingComponent(); | ||
provider.setProps({ customStore: mockStore }); | ||
``` |
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.