@orpc/react 0.0.0-next.e9dc36e → 0.0.0-next.eaf61c7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +151 -0
  2. package/dist/hooks/index.d.mts +69 -0
  3. package/dist/hooks/index.d.ts +69 -0
  4. package/dist/hooks/index.mjs +77 -0
  5. package/dist/index.d.mts +19 -0
  6. package/dist/index.d.ts +19 -0
  7. package/dist/index.mjs +28 -0
  8. package/package.json +24 -24
  9. package/dist/index.js +0 -674
  10. package/dist/index.js.map +0 -1
  11. package/dist/src/general-hooks.d.ts +0 -24
  12. package/dist/src/general-hooks.d.ts.map +0 -1
  13. package/dist/src/general-utils.d.ts +0 -41
  14. package/dist/src/general-utils.d.ts.map +0 -1
  15. package/dist/src/index.d.ts +0 -9
  16. package/dist/src/index.d.ts.map +0 -1
  17. package/dist/src/orpc-path.d.ts +0 -5
  18. package/dist/src/orpc-path.d.ts.map +0 -1
  19. package/dist/src/procedure-hooks.d.ts +0 -31
  20. package/dist/src/procedure-hooks.d.ts.map +0 -1
  21. package/dist/src/procedure-utils.d.ts +0 -35
  22. package/dist/src/procedure-utils.d.ts.map +0 -1
  23. package/dist/src/react-context.d.ts +0 -13
  24. package/dist/src/react-context.d.ts.map +0 -1
  25. package/dist/src/react-hooks.d.ts +0 -22
  26. package/dist/src/react-hooks.d.ts.map +0 -1
  27. package/dist/src/react-utils.d.ts +0 -22
  28. package/dist/src/react-utils.d.ts.map +0 -1
  29. package/dist/src/react.d.ts +0 -21
  30. package/dist/src/react.d.ts.map +0 -1
  31. package/dist/src/tanstack-key.d.ts +0 -15
  32. package/dist/src/tanstack-key.d.ts.map +0 -1
  33. package/dist/src/tanstack-query.d.ts +0 -19
  34. package/dist/src/tanstack-query.d.ts.map +0 -1
  35. package/dist/src/types.d.ts +0 -5
  36. package/dist/src/types.d.ts.map +0 -1
  37. package/dist/src/use-queries/builder.d.ts +0 -20
  38. package/dist/src/use-queries/builder.d.ts.map +0 -1
  39. package/dist/src/use-queries/builders.d.ts +0 -19
  40. package/dist/src/use-queries/builders.d.ts.map +0 -1
  41. package/dist/src/use-queries/hook.d.ts +0 -16
  42. package/dist/src/use-queries/hook.d.ts.map +0 -1
  43. package/dist/tsconfig.tsbuildinfo +0 -1
  44. package/src/general-hooks.test-d.ts +0 -151
  45. package/src/general-hooks.test.tsx +0 -232
  46. package/src/general-hooks.ts +0 -101
  47. package/src/general-utils.test-d.ts +0 -454
  48. package/src/general-utils.test.tsx +0 -818
  49. package/src/general-utils.ts +0 -393
  50. package/src/index.ts +0 -8
  51. package/src/orpc-path.test-d.ts +0 -13
  52. package/src/orpc-path.test.ts +0 -12
  53. package/src/orpc-path.ts +0 -24
  54. package/src/procedure-hooks.test-d.ts +0 -321
  55. package/src/procedure-hooks.test.tsx +0 -388
  56. package/src/procedure-hooks.ts +0 -271
  57. package/src/procedure-utils.test-d.ts +0 -476
  58. package/src/procedure-utils.test.tsx +0 -330
  59. package/src/procedure-utils.ts +0 -312
  60. package/src/react-context.ts +0 -43
  61. package/src/react-hooks.ts +0 -94
  62. package/src/react-utils.ts +0 -98
  63. package/src/react.test-d.ts +0 -89
  64. package/src/react.test.tsx +0 -102
  65. package/src/react.tsx +0 -81
  66. package/src/tanstack-key.test-d.ts +0 -35
  67. package/src/tanstack-key.test.ts +0 -62
  68. package/src/tanstack-key.ts +0 -64
  69. package/src/tanstack-query.ts +0 -27
  70. package/src/types.ts +0 -7
  71. package/src/use-queries/builder.test-d.ts +0 -29
  72. package/src/use-queries/builder.test.ts +0 -25
  73. package/src/use-queries/builder.ts +0 -71
  74. package/src/use-queries/builders.test-d.ts +0 -30
  75. package/src/use-queries/builders.test.tsx +0 -29
  76. package/src/use-queries/builders.ts +0 -101
  77. package/src/use-queries/hook.test-d.ts +0 -64
  78. package/src/use-queries/hook.test.tsx +0 -89
  79. package/src/use-queries/hook.ts +0 -57
@@ -1,321 +0,0 @@
1
- import type { SchemaInput, SchemaOutput } from '@orpc/contract'
2
- import type { DefaultError, InfiniteData } from '@tanstack/react-query'
3
- import {} from '@testing-library/react'
4
- import {
5
- ORPCContext,
6
- type UserCreateInputSchema,
7
- type UserFindInputSchema,
8
- type UserListInputSchema,
9
- type UserListOutputSchema,
10
- type UserSchema,
11
- } from '../tests/orpc'
12
- import { createProcedureHooks } from './procedure-hooks'
13
-
14
- describe('useQuery', () => {
15
- const hooks = createProcedureHooks<
16
- typeof UserFindInputSchema,
17
- typeof UserSchema,
18
- SchemaOutput<typeof UserSchema>
19
- >({
20
- context: ORPCContext,
21
- path: ['user', 'find'],
22
- })
23
-
24
- it('simple', () => {
25
- expectTypeOf<Parameters<typeof hooks.useQuery>[0]>().toEqualTypeOf<
26
- SchemaInput<typeof UserFindInputSchema>
27
- >()
28
-
29
- const query = hooks.useQuery({ id: '1' })
30
-
31
- expectTypeOf(query.data).toEqualTypeOf<
32
- SchemaOutput<typeof UserSchema> | undefined
33
- >()
34
- })
35
-
36
- it('with select', async () => {
37
- const query = hooks.useQuery(
38
- { id: '1' },
39
- {
40
- select(data) {
41
- expectTypeOf(data).toEqualTypeOf<SchemaOutput<typeof UserSchema>>()
42
-
43
- return {
44
- select: data,
45
- }
46
- },
47
- },
48
- )
49
-
50
- expectTypeOf(query.data).toEqualTypeOf<
51
- { select: SchemaOutput<typeof UserSchema> } | undefined
52
- >()
53
- })
54
- })
55
-
56
- describe('useInfiniteQuery', () => {
57
- const hooks = createProcedureHooks<
58
- typeof UserListInputSchema,
59
- typeof UserListOutputSchema,
60
- SchemaOutput<typeof UserListOutputSchema>
61
- >({
62
- context: ORPCContext,
63
- path: ['user', 'list'],
64
- })
65
-
66
- it('simple', () => {
67
- expectTypeOf<
68
- Parameters<typeof hooks.useInfiniteQuery>[0]['input']
69
- >().toMatchTypeOf<{
70
- keyword?: string
71
- cursor?: never /** prevent user to set cursor */
72
- }>()
73
-
74
- const query = hooks.useInfiniteQuery({
75
- input: { keyword: '1' },
76
- getNextPageParam(lastPage) {
77
- return lastPage.nextCursor
78
- },
79
- })
80
-
81
- expectTypeOf(query.data).toEqualTypeOf<
82
- | undefined
83
- | InfiniteData<
84
- SchemaOutput<typeof UserListOutputSchema>,
85
- number | undefined
86
- >
87
- >()
88
- })
89
-
90
- it('with select', () => {
91
- const query = hooks.useInfiniteQuery({
92
- input: { keyword: '1' },
93
- initialPageParam: 12344,
94
- getNextPageParam(lastPage) {
95
- return lastPage.nextCursor
96
- },
97
- select(data) {
98
- expectTypeOf(data).toEqualTypeOf<
99
- InfiniteData<
100
- SchemaOutput<typeof UserListOutputSchema>,
101
- number | undefined
102
- >
103
- >()
104
-
105
- return {
106
- select: data,
107
- }
108
- },
109
- })
110
-
111
- expectTypeOf(query.data).toEqualTypeOf<
112
- | undefined
113
- | {
114
- select: InfiniteData<
115
- SchemaOutput<typeof UserListOutputSchema>,
116
- number | undefined
117
- >
118
- }
119
- >()
120
- })
121
- })
122
-
123
- describe('useSuspenseQuery', () => {
124
- const hooks = createProcedureHooks<
125
- typeof UserFindInputSchema,
126
- typeof UserSchema,
127
- SchemaOutput<typeof UserSchema>
128
- >({
129
- context: ORPCContext,
130
- path: ['user', 'find'],
131
- })
132
-
133
- it('simple', () => {
134
- expectTypeOf<Parameters<typeof hooks.useSuspenseQuery>[0]>().toEqualTypeOf<
135
- SchemaInput<typeof UserFindInputSchema>
136
- >()
137
-
138
- const query = hooks.useSuspenseQuery({ id: '1' })
139
-
140
- expectTypeOf(query.data).toEqualTypeOf<SchemaOutput<typeof UserSchema>>()
141
- })
142
-
143
- it('with select', async () => {
144
- const query = hooks.useSuspenseQuery(
145
- { id: '1' },
146
- {
147
- select(data) {
148
- expectTypeOf(data).toEqualTypeOf<SchemaOutput<typeof UserSchema>>()
149
-
150
- return {
151
- select: data,
152
- }
153
- },
154
- },
155
- )
156
-
157
- expectTypeOf(query.data).toEqualTypeOf<{
158
- select: SchemaOutput<typeof UserSchema>
159
- }>()
160
- })
161
- })
162
-
163
- describe('useSuspenseInfiniteQuery', () => {
164
- const hooks = createProcedureHooks<
165
- typeof UserListInputSchema,
166
- typeof UserListOutputSchema,
167
- SchemaOutput<typeof UserListOutputSchema>
168
- >({
169
- context: ORPCContext,
170
- path: ['user', 'list'],
171
- })
172
-
173
- it('simple', () => {
174
- expectTypeOf<
175
- Parameters<typeof hooks.useSuspenseInfiniteQuery>[0]['input']
176
- >().toMatchTypeOf<{
177
- keyword?: string
178
- cursor?: never /** prevent user to set cursor */
179
- }>()
180
-
181
- const query = hooks.useSuspenseInfiniteQuery({
182
- input: { keyword: '1' },
183
- getNextPageParam(lastPage) {
184
- return lastPage.nextCursor
185
- },
186
- })
187
-
188
- expectTypeOf(query.data).toEqualTypeOf<
189
- InfiniteData<
190
- SchemaOutput<typeof UserListOutputSchema>,
191
- number | undefined
192
- >
193
- >()
194
- })
195
-
196
- it('with select', () => {
197
- const query = hooks.useSuspenseInfiniteQuery({
198
- input: {},
199
- initialPageParam: 12344,
200
- getNextPageParam(lastPage) {
201
- return lastPage.nextCursor
202
- },
203
- select(data) {
204
- expectTypeOf(data).toEqualTypeOf<
205
- InfiniteData<
206
- SchemaOutput<typeof UserListOutputSchema>,
207
- number | undefined
208
- >
209
- >()
210
-
211
- return {
212
- select: data,
213
- }
214
- },
215
- })
216
-
217
- expectTypeOf(query.data).toEqualTypeOf<{
218
- select: InfiniteData<
219
- SchemaOutput<typeof UserListOutputSchema>,
220
- number | undefined
221
- >
222
- }>()
223
- })
224
- })
225
-
226
- describe('usePrefetchQuery', () => {
227
- const hooks = createProcedureHooks<
228
- typeof UserFindInputSchema,
229
- typeof UserSchema,
230
- SchemaOutput<typeof UserSchema>
231
- >({
232
- context: ORPCContext,
233
- path: ['user', 'find'],
234
- })
235
-
236
- it('simple', () => {
237
- expectTypeOf<Parameters<typeof hooks.usePrefetchQuery>[0]>().toEqualTypeOf<
238
- SchemaInput<typeof UserFindInputSchema>
239
- >()
240
-
241
- const query = hooks.usePrefetchQuery({ id: '1' })
242
-
243
- expectTypeOf(query).toEqualTypeOf<void>()
244
- })
245
- })
246
-
247
- describe('usePrefetchInfiniteQuery', () => {
248
- const hooks = createProcedureHooks<
249
- typeof UserListInputSchema,
250
- typeof UserListOutputSchema,
251
- SchemaOutput<typeof UserListOutputSchema>
252
- >({
253
- context: ORPCContext,
254
- path: ['user', 'list'],
255
- })
256
-
257
- it('simple', () => {
258
- expectTypeOf<
259
- Parameters<typeof hooks.usePrefetchInfiniteQuery>[0]['input']
260
- >().toMatchTypeOf<{
261
- keyword?: string
262
- cursor?: never /** prevent user to set cursor */
263
- }>()
264
-
265
- hooks.usePrefetchInfiniteQuery({ input: { keyword: '1' } })
266
-
267
- hooks.usePrefetchInfiniteQuery(
268
- { keyword: '1' },
269
- // @ts-expect-error required getNextPageParam when pages is set
270
- {
271
- initialPageParam: 12344,
272
- pages: 3,
273
- },
274
- )
275
-
276
- const query = hooks.usePrefetchInfiniteQuery({
277
- input: { keyword: '1' },
278
- initialPageParam: 12344,
279
- pages: 3,
280
- getNextPageParam(lastPage) {
281
- return lastPage.nextCursor
282
- },
283
- })
284
-
285
- expectTypeOf(query).toEqualTypeOf<void>()
286
- })
287
- })
288
-
289
- describe('useMutation', () => {
290
- const hooks = createProcedureHooks<
291
- typeof UserCreateInputSchema,
292
- typeof UserSchema,
293
- SchemaOutput<typeof UserSchema>
294
- >({
295
- context: ORPCContext,
296
- path: ['user', 'create'],
297
- })
298
-
299
- it('simple', () => {
300
- const mutation = hooks.useMutation()
301
-
302
- expectTypeOf<Parameters<typeof mutation.mutate>[0]>().toEqualTypeOf<
303
- SchemaInput<typeof UserCreateInputSchema>
304
- >()
305
-
306
- expectTypeOf(mutation.data).toEqualTypeOf<
307
- SchemaOutput<typeof UserSchema> | undefined
308
- >()
309
- })
310
-
311
- it('with options', () => {
312
- hooks.useMutation({
313
- onSuccess(data) {
314
- expectTypeOf(data).toEqualTypeOf<SchemaOutput<typeof UserSchema>>()
315
- },
316
- onError(error) {
317
- expectTypeOf(error).toEqualTypeOf<DefaultError>()
318
- },
319
- })
320
- })
321
- })
@@ -1,388 +0,0 @@
1
- import type { SchemaOutput } from '@orpc/contract'
2
- import { renderHook, screen, waitFor } from '@testing-library/react'
3
- import {
4
- ORPCContext,
5
- queryClient,
6
- type UserCreateInputSchema,
7
- type UserFindInputSchema,
8
- type UserListInputSchema,
9
- type UserListOutputSchema,
10
- type UserSchema,
11
- wrapper,
12
- } from '../tests/orpc'
13
- import { createProcedureHooks } from './procedure-hooks'
14
-
15
- beforeEach(() => {
16
- queryClient.clear()
17
- })
18
-
19
- describe('useQuery', () => {
20
- const hooks = createProcedureHooks<
21
- typeof UserFindInputSchema,
22
- typeof UserSchema,
23
- SchemaOutput<typeof UserSchema>
24
- >({
25
- context: ORPCContext,
26
- path: ['user', 'find'],
27
- })
28
-
29
- it('on success', async () => {
30
- const { result } = renderHook(() => hooks.useQuery({ id: '1' }), {
31
- wrapper,
32
- })
33
-
34
- await waitFor(() => expect(result.current.status).toBe('success'))
35
-
36
- expect(result.current.data).toEqual({
37
- id: '1',
38
- name: 'name-1',
39
- })
40
-
41
- expect(
42
- queryClient.getQueriesData({
43
- exact: true,
44
- queryKey: [['user', 'find'], { input: { id: '1' }, type: 'query' }],
45
- })[0]?.[1],
46
- ).toBe(result.current.data)
47
- })
48
-
49
- it('on error', async () => {
50
- // @ts-expect-error invalid input
51
- const { result } = renderHook(() => hooks.useQuery({ id: {} }), {
52
- wrapper,
53
- })
54
-
55
- await waitFor(() => expect(result.current.status).toBe('error'))
56
-
57
- expect((result.current.error as any).message).toEqual(
58
- 'Validation input failed',
59
- )
60
- })
61
- })
62
-
63
- describe('useInfiniteQuery', () => {
64
- const hooks = createProcedureHooks<
65
- typeof UserListInputSchema,
66
- typeof UserListOutputSchema,
67
- SchemaOutput<typeof UserListOutputSchema>
68
- >({
69
- context: ORPCContext,
70
- path: ['user', 'list'],
71
- })
72
-
73
- it('on success', async () => {
74
- const { result } = renderHook(
75
- () =>
76
- hooks.useInfiniteQuery({
77
- input: { keyword: '1' },
78
- getNextPageParam(lastPage) {
79
- return lastPage.nextCursor
80
- },
81
- }),
82
- {
83
- wrapper,
84
- },
85
- )
86
-
87
- await waitFor(() => expect(result.current.status).toBe('success'))
88
-
89
- expect(result.current.data).toMatchObject({
90
- pages: [
91
- {
92
- nextCursor: 2,
93
- users: [{ name: 'number-0' }, { name: 'number-1' }],
94
- },
95
- ],
96
- pageParams: [undefined],
97
- })
98
-
99
- expect(
100
- queryClient.getQueriesData({
101
- exact: true,
102
- queryKey: [
103
- ['user', 'list'],
104
- { input: { keyword: '1' }, type: 'infinite' },
105
- ],
106
- })[0]?.[1],
107
- ).toBe(result.current.data)
108
-
109
- result.current.fetchNextPage()
110
-
111
- await waitFor(() => expect(result.current.data?.pages.length).toBe(2))
112
-
113
- expect(result.current.data).toMatchObject({
114
- pages: [
115
- {
116
- nextCursor: 2,
117
- users: [{ name: 'number-0' }, { name: 'number-1' }],
118
- },
119
- {
120
- nextCursor: 4,
121
- users: [{ name: 'number-2' }, { name: 'number-3' }],
122
- },
123
- ],
124
- pageParams: [undefined, 2],
125
- })
126
- })
127
-
128
- it('on error', async () => {
129
- const { result } = renderHook(
130
- () =>
131
- hooks.useInfiniteQuery({
132
- // @ts-expect-error invalid input
133
- input: { keyword: {} },
134
- getNextPageParam(lastPage) {
135
- return lastPage.nextCursor
136
- },
137
- }),
138
- {
139
- wrapper,
140
- },
141
- )
142
-
143
- await waitFor(() => expect(result.current.status).toBe('error'))
144
-
145
- expect((result.current.error as any).message).toEqual(
146
- 'Validation input failed',
147
- )
148
- })
149
- })
150
-
151
- describe('useSuspenseQuery', () => {
152
- const hooks = createProcedureHooks<
153
- typeof UserFindInputSchema,
154
- typeof UserSchema,
155
- SchemaOutput<typeof UserSchema>
156
- >({
157
- context: ORPCContext,
158
- path: ['user', 'find'],
159
- })
160
-
161
- it('on success', async () => {
162
- const { result } = renderHook(() => hooks.useSuspenseQuery({ id: '1' }), {
163
- wrapper,
164
- })
165
-
166
- await waitFor(() => expect(result.current.status).toBe('success'))
167
-
168
- expect(result.current.data).toEqual({
169
- id: '1',
170
- name: 'name-1',
171
- })
172
-
173
- expect(
174
- queryClient.getQueriesData({
175
- exact: true,
176
- queryKey: [['user', 'find'], { input: { id: '1' }, type: 'query' }],
177
- })[0]?.[1],
178
- ).toBe(result.current.data)
179
- })
180
-
181
- it('on error', async () => {
182
- // @ts-expect-error invalid input
183
- const { result } = renderHook(() => hooks.useSuspenseQuery({ id: {} }), {
184
- wrapper,
185
- })
186
-
187
- await waitFor(() =>
188
- expect(screen.getByTestId('error-boundary')).toHaveTextContent(
189
- 'Validation input failed',
190
- ),
191
- )
192
- })
193
- })
194
-
195
- describe('useSuspenseInfiniteQuery', () => {
196
- const hooks = createProcedureHooks<
197
- typeof UserListInputSchema,
198
- typeof UserListOutputSchema,
199
- SchemaOutput<typeof UserListOutputSchema>
200
- >({
201
- context: ORPCContext,
202
- path: ['user', 'list'],
203
- })
204
-
205
- it('on success', async () => {
206
- const { result } = renderHook(
207
- () =>
208
- hooks.useSuspenseInfiniteQuery({
209
- input: { keyword: '1' },
210
- getNextPageParam(lastPage) {
211
- return lastPage.nextCursor
212
- },
213
- }),
214
- {
215
- wrapper,
216
- },
217
- )
218
-
219
- await waitFor(() => expect(result.current.status).toBe('success'))
220
-
221
- expect(result.current.data).toMatchObject({
222
- pages: [
223
- {
224
- nextCursor: 2,
225
- users: [{ name: 'number-0' }, { name: 'number-1' }],
226
- },
227
- ],
228
- pageParams: [undefined],
229
- })
230
-
231
- expect(
232
- queryClient.getQueriesData({
233
- exact: true,
234
- queryKey: [
235
- ['user', 'list'],
236
- { input: { keyword: '1' }, type: 'infinite' },
237
- ],
238
- })[0]?.[1],
239
- ).toBe(result.current.data)
240
-
241
- result.current.fetchNextPage()
242
-
243
- await waitFor(() => expect(result.current.data?.pages.length).toBe(2))
244
-
245
- expect(result.current.data).toMatchObject({
246
- pages: [
247
- {
248
- nextCursor: 2,
249
- users: [{ name: 'number-0' }, { name: 'number-1' }],
250
- },
251
- {
252
- nextCursor: 4,
253
- users: [{ name: 'number-2' }, { name: 'number-3' }],
254
- },
255
- ],
256
- pageParams: [undefined, 2],
257
- })
258
- })
259
-
260
- it('on error', async () => {
261
- const { result } = renderHook(
262
- () =>
263
- hooks.useSuspenseInfiniteQuery({
264
- // @ts-expect-error invalid input
265
- input: { keyword: {} },
266
- getNextPageParam(lastPage) {
267
- return lastPage.nextCursor
268
- },
269
- }),
270
- {
271
- wrapper,
272
- },
273
- )
274
-
275
- await waitFor(() =>
276
- expect(screen.getByTestId('error-boundary')).toHaveTextContent(
277
- 'Validation input failed',
278
- ),
279
- )
280
- })
281
- })
282
-
283
- describe('usePrefetchQuery', () => {
284
- const hooks = createProcedureHooks<
285
- typeof UserFindInputSchema,
286
- typeof UserSchema,
287
- SchemaOutput<typeof UserSchema>
288
- >({
289
- context: ORPCContext,
290
- path: ['user', 'find'],
291
- })
292
-
293
- it('on success', async () => {
294
- renderHook(() => hooks.usePrefetchQuery({ id: '1' }), {
295
- wrapper,
296
- })
297
-
298
- await waitFor(() =>
299
- expect(
300
- queryClient.getQueriesData({
301
- exact: true,
302
- queryKey: [['user', 'find'], { input: { id: '1' }, type: 'query' }],
303
- })[0]?.[1],
304
- ).toEqual({
305
- id: '1',
306
- name: 'name-1',
307
- }),
308
- )
309
- })
310
- })
311
-
312
- describe('usePrefetchInfiniteQuery', () => {
313
- const hooks = createProcedureHooks<
314
- typeof UserListInputSchema,
315
- typeof UserListOutputSchema,
316
- SchemaOutput<typeof UserListOutputSchema>
317
- >({
318
- context: ORPCContext,
319
- path: ['user', 'list'],
320
- })
321
-
322
- it('on success', async () => {
323
- renderHook(
324
- () => hooks.usePrefetchInfiniteQuery({ input: { keyword: '1' } }),
325
- {
326
- wrapper,
327
- },
328
- )
329
-
330
- await waitFor(() =>
331
- expect(
332
- queryClient.getQueriesData({
333
- exact: true,
334
- queryKey: [
335
- ['user', 'list'],
336
- { input: { keyword: '1' }, type: 'infinite' },
337
- ],
338
- })[0]?.[1],
339
- ).toMatchObject({
340
- pages: [
341
- {
342
- nextCursor: 2,
343
- users: [{ name: 'number-0' }, { name: 'number-1' }],
344
- },
345
- ],
346
- pageParams: [undefined],
347
- }),
348
- )
349
- })
350
- })
351
-
352
- describe('useMutation', () => {
353
- const hooks = createProcedureHooks<
354
- typeof UserCreateInputSchema,
355
- typeof UserSchema,
356
- SchemaOutput<typeof UserSchema>
357
- >({
358
- context: ORPCContext,
359
- path: ['user', 'create'],
360
- })
361
-
362
- it('on success', async () => {
363
- const { result } = renderHook(() => hooks.useMutation(), {
364
- wrapper,
365
- })
366
-
367
- result.current.mutate({ name: 'name-1' })
368
-
369
- await waitFor(() =>
370
- expect(result.current.data).toMatchObject({ name: 'name-1' }),
371
- )
372
- })
373
-
374
- it('on error', async () => {
375
- const { result } = renderHook(() => hooks.useMutation(), {
376
- wrapper,
377
- })
378
-
379
- // @ts-expect-error invalid input
380
- result.current.mutate({ name: {} })
381
-
382
- await waitFor(() =>
383
- expect((result.current.error as any)?.message).toEqual(
384
- 'Validation input failed',
385
- ),
386
- )
387
- })
388
- })