Skip to content

Commit 6e627c8

Browse files
committed
Changed nextUpdate to waitForNextUpdate
1 parent fb2a1b2 commit 6e627c8

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Renders a test component that will call the provided `callback`, including any h
154154

155155
- `result` (`object`)
156156
- `current` (`any`) - the return value of the `callback` function
157-
- `nextUpdate` (`function`) - returns a `Promise` that resolves the next time the hook renders, commonly when state is updated as the result of a asynchronous action.
157+
- `waitForNextUpdate` (`function`) - returns a `Promise` that resolves the next time the hook renders, commonly when state is updated as the result of a asynchronous action.
158158
- `rerender` (`function([newProps])`) - function to rerender the test component including any hooks called in the `callback` function. If `newProps` are passed, the will replace the `initialProps` passed the the `callback` function for future renders.
159159
- `unmount` (`function()`) - function to unmount the test component, commonly used to trigger cleanup effects for `useEffect` hooks.
160160

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function renderHook(callback, { initialProps, ...options } = {}) {
1010
const result = { current: null }
1111
const hookProps = { current: initialProps }
1212
const resolvers = []
13-
const nextUpdate = () =>
13+
const waitForNextUpdate = () =>
1414
new Promise((resolve) => {
1515
resolvers.push(resolve)
1616
})
@@ -28,7 +28,7 @@ function renderHook(callback, { initialProps, ...options } = {}) {
2828

2929
return {
3030
result,
31-
nextUpdate,
31+
waitForNextUpdate,
3232
unmount,
3333
rerender: (newProps = hookProps.current) => {
3434
hookProps.current = newProps

test/asyncHook.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,41 @@ describe('async hook tests', () => {
1919
afterEach(cleanup)
2020

2121
test('should wait for next update', async () => {
22-
const { result, nextUpdate } = renderHook(() => useName())
22+
const { result, waitForNextUpdate } = renderHook(() => useName())
2323

2424
expect(result.current).toBe('nobody')
2525

26-
await nextUpdate()
26+
await waitForNextUpdate()
2727

2828
expect(result.current).toBe('Betty')
2929
})
3030

3131
test('should wait for multiple updates', async () => {
32-
const { result, nextUpdate, rerender } = renderHook(({ prefix }) => useName(prefix), {
32+
const { result, waitForNextUpdate, rerender } = renderHook(({ prefix }) => useName(prefix), {
3333
initialProps: { prefix: 'Mrs.' }
3434
})
3535

3636
expect(result.current).toBe('nobody')
3737

38-
await nextUpdate()
38+
await waitForNextUpdate()
3939

4040
expect(result.current).toBe('Mrs. Betty')
4141

4242
rerender({ prefix: 'Ms.' })
4343

44-
await nextUpdate()
44+
await waitForNextUpdate()
4545

4646
expect(result.current).toBe('Ms. Betty')
4747
})
4848

4949
test('should resolve all when updating', async () => {
50-
const { result, nextUpdate } = renderHook(({ prefix }) => useName(prefix), {
50+
const { result, waitForNextUpdate } = renderHook(({ prefix }) => useName(prefix), {
5151
initialProps: { prefix: 'Mrs.' }
5252
})
5353

5454
expect(result.current).toBe('nobody')
5555

56-
await Promise.all([nextUpdate(), nextUpdate(), nextUpdate()])
56+
await Promise.all([waitForNextUpdate(), waitForNextUpdate(), waitForNextUpdate()])
5757

5858
expect(result.current).toBe('Mrs. Betty')
5959
})

test/typescript/renderHook.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ function checkTypesWhenHookReturnsVoid() {
6565
const _rerender: () => void = rerender
6666
}
6767

68-
async function checkTypesForNextUpdate() {
69-
const { nextUpdate } = renderHook(() => {})
68+
async function checkTypesForWaitForNextUpdate() {
69+
const { waitForNextUpdate } = renderHook(() => {})
7070

71-
await nextUpdate()
71+
await waitForNextUpdate()
7272

7373
// check type
74-
const _nextUpdate: () => Promise<void> = nextUpdate
74+
const _waitForNextUpdate: () => Promise<void> = waitForNextUpdate
7575
}

typings/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function renderHook<P, R>(
99
readonly result: {
1010
current: R
1111
}
12-
readonly nextUpdate: () => Promise<void>
12+
readonly waitForNextUpdate: () => Promise<void>
1313
readonly unmount: RenderResult['unmount']
1414
readonly rerender: (hookProps?: P) => void
1515
}

0 commit comments

Comments
 (0)