-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathuseBlockNumber.test.ts
More file actions
73 lines (63 loc) · 1.96 KB
/
useBlockNumber.test.ts
File metadata and controls
73 lines (63 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { testClient } from '@wagmi/test'
import { renderHook } from '@wagmi/test/react'
import { expect, test, vi } from 'vitest'
import { useBlockNumber } from './useBlockNumber.js'
test('mounts', async () => {
await testClient.mainnet.resetFork()
const { result } = await renderHook(() => useBlockNumber())
await vi.waitUntil(() => result.current.isSuccess, { timeout: 10_000 })
expect(result.current).toMatchInlineSnapshot(`
{
"data": 23535880n,
"dataUpdatedAt": 1675209600000,
"error": null,
"errorUpdateCount": 0,
"errorUpdatedAt": 0,
"failureCount": 0,
"failureReason": null,
"fetchStatus": "idle",
"isEnabled": true,
"isError": false,
"isFetched": true,
"isFetchedAfterMount": true,
"isFetching": false,
"isInitialLoading": false,
"isLoading": false,
"isLoadingError": false,
"isPaused": false,
"isPending": false,
"isPlaceholderData": false,
"isRefetchError": false,
"isRefetching": false,
"isStale": true,
"isSuccess": true,
"promise": Promise {
"reason": [Error: experimental_prefetchInRender feature flag is not enabled],
"status": "rejected",
},
"queryKey": [
"blockNumber",
{
"chainId": 1,
},
],
"refetch": [Function],
"status": "success",
}
`)
})
test('parameters: watch', async () => {
await testClient.mainnet.restart()
const { result } = await renderHook(() => useBlockNumber({ watch: true }))
await vi.waitUntil(() => result.current.isSuccess, { timeout: 10_000 })
const blockNumber = result.current.data!
expect(result.current.data).toBeTypeOf('bigint')
await testClient.mainnet.mine({ blocks: 1 })
await vi.waitFor(() => {
expect(result.current.data).toEqual(blockNumber + 1n)
})
await testClient.mainnet.mine({ blocks: 1 })
await vi.waitFor(() => {
expect(result.current.data).toEqual(blockNumber + 2n)
})
})