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 7b75f00

Browse files
Update wrapper props with rerenderProps
1 parent e77aab8 commit 7b75f00

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
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

‎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 によって変換されたページ (->オリジナル) /