Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7c98baf

Browse files
authored
Merge pull request testing-library#381 from hemlok/pr/use-rerender-props-in-wrapper
feature/use rerender props in wrapper
2 parents e77aab8 + 5eaac2d commit 7c98baf

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

‎.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@
165165
"contributions": [
166166
"doc"
167167
]
168+
},
169+
{
170+
"login": "hemlok",
171+
"name": "Adam Seckel",
172+
"avatar_url": "https://avatars2.githubusercontent.com/u/9043345?v=4",
173+
"profile": "https://github.com/hemlok",
174+
"contributions": [
175+
"code"
176+
]
168177
}
169178
],
170179
"commitConvention": "none"

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
161161
<tr>
162162
<td align="center"><a href="http://frontstuff.io"><img src="https://avatars1.githubusercontent.com/u/5370675?v=4" width="100px;" alt=""/><br /><sub><b>Sarah Dayan</b></sub></a><br /><a href="#platform-sarahdayan" title="Packaging/porting to new platform">📦</a></td>
163163
<td align="center"><a href="https://github.com/102"><img src="https://avatars1.githubusercontent.com/u/5839225?v=4" width="100px;" alt=""/><br /><sub><b>Roman Gusev</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=102" title="Documentation">📖</a></td>
164+
<td align="center"><a href="https://github.com/hemlok"><img src="https://avatars2.githubusercontent.com/u/9043345?v=4" width="100px;" alt=""/><br /><sub><b>Adam Seckel</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=hemlok" title="Code">💻</a></td>
164165
</tr>
165166
</table>
166167

‎docs/api-reference.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ The `renderHook` function accepts the following options as the second parameter:
4646

4747
### `initialProps`
4848

49-
The initial values to pass as `props` to the `callback` function of `renderHook.
49+
The initial values to pass as `props` to the `callback` function of `renderHook`.
5050

5151
### `wrapper`
5252

5353
A React component to wrap the test component in when rendering. This is usually used to add context
54-
providers from `React.createContext` for the hook to access with `useContext`.
54+
providers from `React.createContext` for the hook to access with `useContext`. `initialProps` and
55+
props subsequently set by `rerender` will be provided to the wrapper.
5556

5657
## `renderHook` Result
5758

‎src/pure.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function renderHook(callback, { initialProps, wrapper } = {}) {
5858
const hookProps = { current: initialProps }
5959

6060
const wrapUiIfNeeded = (innerElement) =>
61-
wrapper ? React.createElement(wrapper, null, innerElement) : innerElement
61+
wrapper ? React.createElement(wrapper, hookProps.current, innerElement) : innerElement
6262

6363
const toRender = () =>
6464
wrapUiIfNeeded(

‎test/useContext.test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('useContext tests', () => {
2424
expect(result.current).toBe('bar')
2525
})
2626

27-
test('should update value in context', () => {
27+
test('should update mutated value in context', () => {
2828
const TestContext = createContext('foo')
2929

3030
const value = { current: 'bar' }
@@ -41,4 +41,23 @@ describe('useContext tests', () => {
4141

4242
expect(result.current).toBe('baz')
4343
})
44+
45+
test('should update value in context when props are updated', () => {
46+
const TestContext = createContext('foo')
47+
48+
const wrapper = ({ current, children }) => (
49+
<TestContext.Provider value={current}>{children}</TestContext.Provider>
50+
)
51+
52+
const { result, rerender } = renderHook(() => useContext(TestContext), {
53+
wrapper,
54+
initialProps: {
55+
current: 'bar'
56+
}
57+
})
58+
59+
rerender({ current: 'baz' })
60+
61+
expect(result.current).toBe('baz')
62+
})
4463
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /