Skip to content

Commit 5238bad

Browse files
committed
Small code cleanup
1 parent 1184bbc commit 5238bad

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/asyncUtils.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function asyncUtils(addResolver) {
1111

1212
const waitForNextUpdate = async (options = {}) => {
1313
if (!nextUpdatePromise) {
14-
const resolveOnNextUpdate = (resolve, reject) => {
14+
nextUpdatePromise = new Promise((resolve, reject) => {
1515
let timeoutId
1616
if (options.timeout > 0) {
1717
timeoutId = setTimeout(
@@ -24,12 +24,10 @@ function asyncUtils(addResolver) {
2424
nextUpdatePromise = null
2525
resolve()
2626
})
27-
}
28-
29-
nextUpdatePromise = new Promise(resolveOnNextUpdate)
27+
})
3028
await act(() => nextUpdatePromise)
3129
}
32-
return await nextUpdatePromise
30+
await nextUpdatePromise
3331
}
3432

3533
const wait = async (callback, { timeout, suppressErrors = true } = {}) => {

src/pure.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ function renderHook(callback, { initialProps, wrapper } = {}) {
7575
})
7676
const { unmount, update } = testRenderer
7777

78+
function rerenderHook(newProps = hookProps.current) {
79+
hookProps.current = newProps
80+
act(() => {
81+
update(toRender())
82+
})
83+
}
84+
7885
function unmountHook() {
7986
act(() => {
8087
removeCleanup(unmountHook)
@@ -86,12 +93,7 @@ function renderHook(callback, { initialProps, wrapper } = {}) {
8693

8794
return {
8895
result,
89-
rerender: (newProps = hookProps.current) => {
90-
hookProps.current = newProps
91-
act(() => {
92-
update(toRender())
93-
})
94-
},
96+
rerender: rerenderHook,
9597
unmount: unmountHook,
9698
...asyncUtils(addResolver)
9799
}

0 commit comments

Comments
 (0)