Skip to content

Commit

Permalink
docs: more React 18 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Oct 21, 2024
1 parent b6784e1 commit ae82e2d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions docs/migration/v12.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,46 @@ it('should provide the org unit data', async () => {
})
```

In some cases, `renderHookResult.waitFor` can just be removed and doesn't need replacing:

```diff
it('should update validationToRefresh', async () => {
- const { result, waitFor } = renderHook(useValidationStore)
+ const { result } = renderHook(useValidationStore)

act(() => {
result.current.setValidationToRefresh(true)
})

- await waitFor(() => {
- expect(result.current.getValidationToRefresh()).toBe(true)
- })
+ expect(result.current.getValidationToRefresh()).toBe(true)
})
```

And testing errors:

```diff
it('throws an error when passing both a client- and a serverDate', async () => {
const clientDate = new Date('2022-10-13 10:00:00')
const serverDate = new Date('2022-10-13 08:00:00')
- const { result } = renderHook(() =>
- useClientServerDate({ clientDate, serverDate })
- )
- expect(result.error).toEqual(
- new Error(
- '`useClientServerDate` does not accept both a client and a server date'
- )

+ expect(() => {
+ renderHook(() => useClientServerDate({ clientDate, serverDate }))
+ }).toThrow(
+ '`useClientServerDate` does not accept both a client and a server date'
+ )
})
```

##### Fake timers

Faking timers can help with tests that seem to fail with concurrency issues:
Expand Down

0 comments on commit ae82e2d

Please sign in to comment.