@hyper-fetch/react 9.6.1 → 9.6.2
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.
- package/__tests__/features/helpers/use-tracked-state/use-tacked-state.actions.spec.ts +1 -1
- package/__tests__/features/helpers/use-tracked-state/use-tracked-state.keys.spec.ts +294 -0
- package/__tests__/features/helpers/utils.spec.ts +127 -0
- package/__tests__/features/provider/provider.config.spec.tsx +172 -0
- package/__tests__/features/use-app-manager/use-app-manager.events.spec.tsx +497 -0
- package/__tests__/features/use-cache/use-cache.state.spec.tsx +326 -0
- package/__tests__/features/use-emitter/use-emitter.lifecycle.spec.tsx +417 -0
- package/__tests__/features/use-fetch/use-fetch.bounce-timers.spec.ts +199 -0
- package/__tests__/features/use-fetch/use-fetch.cache-events.spec.ts +212 -0
- package/__tests__/features/use-fetch/use-fetch.callbacks.spec.tsx +359 -0
- package/__tests__/features/use-fetch/use-fetch.hydration.spec.tsx +126 -0
- package/__tests__/features/use-fetch/use-fetch.infinite.spec.ts +146 -0
- package/__tests__/features/use-fetch/use-fetch.initial-state.spec.ts +340 -0
- package/__tests__/features/use-fetch/use-fetch.keys.spec.tsx +559 -0
- package/__tests__/features/use-fetch/use-fetch.lifecycle.spec.ts +348 -0
- package/__tests__/features/use-fetch/use-fetch.mounting.spec.tsx +411 -0
- package/__tests__/features/use-fetch/use-fetch.pagination.spec.ts +177 -0
- package/__tests__/features/use-fetch/use-fetch.refresh-interval.spec.ts +355 -0
- package/__tests__/features/use-fetch/use-fetch.response-order.spec.ts +105 -0
- package/__tests__/features/use-fetch/use-fetch.retry.spec.ts +235 -0
- package/__tests__/features/use-fetch/use-fetch.return-types.spec.ts +186 -0
- package/__tests__/features/use-fetch/use-fetch.scope.spec.ts +333 -0
- package/__tests__/features/use-fetch/use-fetch.ssr.spec.tsx +195 -0
- package/__tests__/features/use-fetch/use-fetch.suspense-edge.spec.tsx +391 -0
- package/__tests__/features/use-fetch/use-fetch.throwing-callbacks.spec.tsx +112 -0
- package/__tests__/features/use-fetch/use-fetch.tracking.spec.tsx +364 -0
- package/__tests__/features/use-fetch/use-fetch.window-events.spec.ts +300 -0
- package/__tests__/features/use-infinite-fetch/use-infinite-fetch.parity.spec.tsx +1027 -0
- package/__tests__/features/use-infinite-fetch/use-infinite-fetch.resubscribe.spec.tsx +267 -0
- package/__tests__/features/use-infinite-fetch/use-infinite-fetch.typescript.spec.ts +64 -1
- package/__tests__/features/use-is-fetching/use-is-fetching.lifecycle.spec.tsx +301 -0
- package/__tests__/features/use-listener/use-listener.lifecycle.spec.tsx +507 -0
- package/__tests__/features/use-listener/use-listener.ssr.spec.tsx +89 -0
- package/__tests__/features/use-queue/use-queue.controls.spec.tsx +593 -0
- package/__tests__/features/use-queue/use-queue.list.spec.tsx +560 -0
- package/__tests__/features/use-queue/use-queue.progress.spec.tsx +650 -0
- package/__tests__/features/use-submit/use-submit.abort.spec.tsx +270 -0
- package/__tests__/features/use-submit/use-submit.actions.spec.tsx +446 -0
- package/__tests__/features/use-submit/use-submit.arguments.spec.tsx +732 -0
- package/__tests__/features/use-submit/use-submit.bounce.spec.tsx +644 -0
- package/__tests__/features/use-submit/use-submit.callbacks.spec.tsx +860 -0
- package/__tests__/features/use-submit/use-submit.chaining.spec.tsx +167 -0
- package/__tests__/features/use-submit/use-submit.double-submit.spec.tsx +552 -0
- package/__tests__/features/use-submit/use-submit.offline.spec.tsx +285 -0
- package/__tests__/features/use-submit/use-submit.optimistic-cache.spec.tsx +619 -0
- package/__tests__/features/use-submit/use-submit.optimistic-settlement.spec.ts +6 -0
- package/__tests__/features/use-submit/use-submit.optimistic.spec.ts +5 -1
- package/__tests__/features/use-submit/use-submit.state.spec.tsx +1025 -0
- package/__tests__/features/use-submit/use-submit.submit-types.spec.ts +194 -0
- package/__tests__/features/use-submit/use-submit.submitting.spec.tsx +180 -0
- package/__tests__/utils/gate.utils.ts +103 -0
- package/__tests__/utils/gated-client.utils.ts +158 -0
- package/__tests__/utils/helpers.utils.ts +19 -0
- package/dist/helpers/use-request-events/use-request-events.hooks.d.ts.map +1 -1
- package/dist/helpers/use-request-events/use-request-events.types.d.ts +1 -1
- package/dist/helpers/use-request-events/use-request-events.types.d.ts.map +1 -1
- package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts.map +1 -1
- package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts +8 -0
- package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts.map +1 -1
- package/dist/hooks/use-cache/use-cache.hooks.d.ts.map +1 -1
- package/dist/hooks/use-fetch/use-fetch.hooks.d.ts.map +1 -1
- package/dist/hooks/use-infinite-fetch/use-infinite-fetch.hooks.d.ts.map +1 -1
- package/dist/hooks/use-infinite-fetch/use-infinite-fetch.store.d.ts +3 -0
- package/dist/hooks/use-infinite-fetch/use-infinite-fetch.store.d.ts.map +1 -1
- package/dist/hooks/use-infinite-fetch/use-infinite-fetch.types.d.ts +5 -3
- package/dist/hooks/use-infinite-fetch/use-infinite-fetch.types.d.ts.map +1 -1
- package/dist/hooks/use-infinite-fetch/use-infinite-fetch.utils.d.ts +11 -1
- package/dist/hooks/use-infinite-fetch/use-infinite-fetch.utils.d.ts.map +1 -1
- package/dist/hooks/use-listener/use-listener.hooks.d.ts.map +1 -1
- package/dist/hooks/use-queue/use-queue.hooks.d.ts.map +1 -1
- package/dist/hooks/use-submit/use-submit.hooks.d.ts.map +1 -1
- package/dist/index.mjs +630 -346
- package/dist/index.mjs.map +1 -1
- package/dist/provider/provider.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/helpers/use-request-events/use-request-events.hooks.ts +141 -28
- package/src/helpers/use-request-events/use-request-events.types.ts +1 -1
- package/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +148 -101
- package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +26 -5
- package/src/hooks/use-cache/use-cache.hooks.ts +20 -5
- package/src/hooks/use-fetch/use-fetch.hooks.ts +194 -113
- package/src/hooks/use-infinite-fetch/use-infinite-fetch.hooks.ts +55 -26
- package/src/hooks/use-infinite-fetch/use-infinite-fetch.store.ts +35 -29
- package/src/hooks/use-infinite-fetch/use-infinite-fetch.types.ts +5 -3
- package/src/hooks/use-infinite-fetch/use-infinite-fetch.utils.ts +25 -1
- package/src/hooks/use-listener/use-listener.hooks.ts +2 -1
- package/src/hooks/use-queue/use-queue.hooks.ts +85 -60
- package/src/hooks/use-submit/use-submit.hooks.ts +163 -53
- package/src/provider/provider.tsx +9 -1
- package/__tests__/features/use-fetch/use-fetch.pagination.ts +0 -36
- package/__tests__/features/use-fetch/use-fetch.retry.ts +0 -38
|
@@ -0,0 +1,732 @@
|
|
|
1
|
+
import type { RequestInstance } from "@hyper-fetch/core";
|
|
2
|
+
import { getErrorMessage } from "@hyper-fetch/core";
|
|
3
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
4
|
+
import type { UseSubmitOptionsType } from "hooks/use-submit";
|
|
5
|
+
import { useSubmit } from "hooks/use-submit";
|
|
6
|
+
import { Provider } from "provider";
|
|
7
|
+
import type { ReactNode } from "react";
|
|
8
|
+
|
|
9
|
+
import { createGatedClient } from "../../utils/gated-client.utils";
|
|
10
|
+
|
|
11
|
+
type User = { id: number; name: string };
|
|
12
|
+
|
|
13
|
+
const setup = () => {
|
|
14
|
+
const gated = createGatedClient();
|
|
15
|
+
const createUser = gated.client.createRequest<{ response: User; payload: { name: string } }>()({
|
|
16
|
+
endpoint: "/users",
|
|
17
|
+
method: "POST",
|
|
18
|
+
});
|
|
19
|
+
const patchUser = gated.client.createRequest<{
|
|
20
|
+
response: User;
|
|
21
|
+
payload: { name: string };
|
|
22
|
+
queryParams?: { notify?: string; source?: string };
|
|
23
|
+
}>()({
|
|
24
|
+
endpoint: "/teams/:teamId/users/:userId",
|
|
25
|
+
method: "PATCH",
|
|
26
|
+
});
|
|
27
|
+
return { ...gated, createUser, patchUser };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** The tests read the state outside of the render, so the hook has to rerender on every change */
|
|
31
|
+
const useUntrackedSubmit = <T extends RequestInstance>(request: T, options?: UseSubmitOptionsType<T>) =>
|
|
32
|
+
useSubmit(request, { dependencyTracking: false, ...options } as UseSubmitOptionsType<T>);
|
|
33
|
+
|
|
34
|
+
/** Run the pending timers and promise callbacks - for the tests using fake timers */
|
|
35
|
+
const advance = async (time = 0) => {
|
|
36
|
+
await act(async () => {
|
|
37
|
+
await vi.advanceTimersByTimeAsync(time);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
describe("useSubmit [ Submit arguments ]", () => {
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
vi.useRealTimers();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("when passing the request data to submit", () => {
|
|
47
|
+
it("should send the payload", async () => {
|
|
48
|
+
const { createUser, waitForCall } = setup();
|
|
49
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
50
|
+
|
|
51
|
+
act(() => {
|
|
52
|
+
result.current.submit({ payload: { name: "Maciej" } });
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const call = await waitForCall(0);
|
|
56
|
+
expect(call.request.payload).toStrictEqual({ name: "Maciej" });
|
|
57
|
+
expect(call.payload).toBe(JSON.stringify({ name: "Maciej" }));
|
|
58
|
+
});
|
|
59
|
+
it("should send the params", async () => {
|
|
60
|
+
const { patchUser, waitForCall } = setup();
|
|
61
|
+
const { result } = renderHook(() => useUntrackedSubmit(patchUser));
|
|
62
|
+
|
|
63
|
+
act(() => {
|
|
64
|
+
result.current.submit({ payload: { name: "Maciej" }, params: { teamId: "core", userId: 7 } });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const call = await waitForCall(0);
|
|
68
|
+
expect(call.request.endpoint).toBe("/teams/core/users/7");
|
|
69
|
+
expect(call.request.params).toStrictEqual({ teamId: "core", userId: 7 });
|
|
70
|
+
});
|
|
71
|
+
it("should send the query params", async () => {
|
|
72
|
+
const { patchUser, waitForCall } = setup();
|
|
73
|
+
const { result } = renderHook(() => useUntrackedSubmit(patchUser));
|
|
74
|
+
|
|
75
|
+
act(() => {
|
|
76
|
+
result.current.submit({
|
|
77
|
+
payload: { name: "Maciej" },
|
|
78
|
+
params: { teamId: "core", userId: 7 },
|
|
79
|
+
queryParams: { notify: "true" },
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const call = await waitForCall(0);
|
|
84
|
+
expect(call.request.queryParams).toStrictEqual({ notify: "true" });
|
|
85
|
+
});
|
|
86
|
+
it("should send the payload, params and query params together", async () => {
|
|
87
|
+
const { patchUser, waitForCall } = setup();
|
|
88
|
+
const { result } = renderHook(() => useUntrackedSubmit(patchUser));
|
|
89
|
+
|
|
90
|
+
act(() => {
|
|
91
|
+
result.current.submit({
|
|
92
|
+
payload: { name: "Kacper" },
|
|
93
|
+
params: { teamId: "docs", userId: 3 },
|
|
94
|
+
queryParams: { notify: "false", source: "form" },
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const call = await waitForCall(0);
|
|
99
|
+
expect(call.request.payload).toStrictEqual({ name: "Kacper" });
|
|
100
|
+
expect(call.request.endpoint).toBe("/teams/docs/users/3");
|
|
101
|
+
expect(call.request.queryParams).toStrictEqual({ notify: "false", source: "form" });
|
|
102
|
+
expect(call.request.method).toBe("PATCH");
|
|
103
|
+
});
|
|
104
|
+
it("should send the data set on the request when submit gets no arguments", async () => {
|
|
105
|
+
const { patchUser, waitForCall } = setup();
|
|
106
|
+
const prepared = patchUser
|
|
107
|
+
.setParams({ teamId: "core", userId: 7 })
|
|
108
|
+
.setPayload({ name: "Maciej" })
|
|
109
|
+
.setQueryParams({ notify: "true" });
|
|
110
|
+
const { result } = renderHook(() => useUntrackedSubmit(prepared));
|
|
111
|
+
|
|
112
|
+
act(() => {
|
|
113
|
+
result.current.submit();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const call = await waitForCall(0);
|
|
117
|
+
expect(call.request.payload).toStrictEqual({ name: "Maciej" });
|
|
118
|
+
expect(call.request.endpoint).toBe("/teams/core/users/7");
|
|
119
|
+
expect(call.request.queryParams).toStrictEqual({ notify: "true" });
|
|
120
|
+
});
|
|
121
|
+
it("should mix the data set on the request with the submit arguments", async () => {
|
|
122
|
+
const { patchUser, waitForCall } = setup();
|
|
123
|
+
const prepared = patchUser.setParams({ teamId: "core", userId: 7 });
|
|
124
|
+
const { result } = renderHook(() => useUntrackedSubmit(prepared));
|
|
125
|
+
|
|
126
|
+
act(() => {
|
|
127
|
+
result.current.submit({ payload: { name: "Kacper" } });
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const call = await waitForCall(0);
|
|
131
|
+
expect(call.request.payload).toStrictEqual({ name: "Kacper" });
|
|
132
|
+
expect(call.request.endpoint).toBe("/teams/core/users/7");
|
|
133
|
+
});
|
|
134
|
+
it("should not change the request passed to the hook", async () => {
|
|
135
|
+
const { patchUser, waitForCall } = setup();
|
|
136
|
+
const { result } = renderHook(() => useUntrackedSubmit(patchUser));
|
|
137
|
+
|
|
138
|
+
act(() => {
|
|
139
|
+
result.current.submit({ payload: { name: "Maciej" }, params: { teamId: "core", userId: 7 } });
|
|
140
|
+
});
|
|
141
|
+
await waitForCall(0);
|
|
142
|
+
|
|
143
|
+
expect(patchUser.payload).toBeUndefined();
|
|
144
|
+
expect(patchUser.params).toBeUndefined();
|
|
145
|
+
expect(patchUser.endpoint).toBe("/teams/:teamId/users/:userId");
|
|
146
|
+
});
|
|
147
|
+
it("should send different data with every submit", async () => {
|
|
148
|
+
const { createUser, waitForCalls } = setup();
|
|
149
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
150
|
+
|
|
151
|
+
act(() => {
|
|
152
|
+
result.current.submit({ payload: { name: "First" } });
|
|
153
|
+
result.current.submit({ payload: { name: "Second" } });
|
|
154
|
+
result.current.submit({ payload: { name: "Third" } });
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const calls = await waitForCalls(3);
|
|
158
|
+
expect(calls.map((call) => call.request.payload)).toStrictEqual([
|
|
159
|
+
{ name: "First" },
|
|
160
|
+
{ name: "Second" },
|
|
161
|
+
{ name: "Third" },
|
|
162
|
+
]);
|
|
163
|
+
});
|
|
164
|
+
it("should send a separate request for every submit", async () => {
|
|
165
|
+
const { createUser, waitForCalls } = setup();
|
|
166
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
167
|
+
|
|
168
|
+
act(() => {
|
|
169
|
+
result.current.submit({ payload: { name: "Same" } });
|
|
170
|
+
result.current.submit({ payload: { name: "Same" } });
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const calls = await waitForCalls(2);
|
|
174
|
+
expect(calls[0].requestId).not.toBe(calls[1].requestId);
|
|
175
|
+
});
|
|
176
|
+
it("should use the submit dispatcher", async () => {
|
|
177
|
+
const { createUser, client, waitForCall } = setup();
|
|
178
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
179
|
+
|
|
180
|
+
act(() => {
|
|
181
|
+
result.current.submit({ payload: { name: "Maciej" } });
|
|
182
|
+
});
|
|
183
|
+
await waitForCall(0);
|
|
184
|
+
|
|
185
|
+
expect(client.submitDispatcher.getAllRunningRequests()).toHaveLength(1);
|
|
186
|
+
expect(client.fetchDispatcher.getAllRunningRequests()).toHaveLength(0);
|
|
187
|
+
});
|
|
188
|
+
it("should send a GET request through the submit dispatcher as well", async () => {
|
|
189
|
+
const { client, waitForCall } = setup();
|
|
190
|
+
const search = client.createRequest<{ response: User[]; queryParams: { search: string } }>()({
|
|
191
|
+
endpoint: "/users",
|
|
192
|
+
});
|
|
193
|
+
const { result } = renderHook(() => useUntrackedSubmit(search));
|
|
194
|
+
|
|
195
|
+
act(() => {
|
|
196
|
+
result.current.submit({ queryParams: { search: "mac" } });
|
|
197
|
+
});
|
|
198
|
+
await waitForCall(0);
|
|
199
|
+
|
|
200
|
+
expect(client.submitDispatcher.getAllRunningRequests()).toHaveLength(1);
|
|
201
|
+
expect(result.current.submitting).toBeTrue();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe("when passing the callbacks to submit", () => {
|
|
206
|
+
it("should call onBeforeSent with the id of the request", async () => {
|
|
207
|
+
const { createUser, waitForCall } = setup();
|
|
208
|
+
const onBeforeSent = vi.fn();
|
|
209
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
210
|
+
|
|
211
|
+
act(() => {
|
|
212
|
+
result.current.submit({ payload: { name: "Maciej" }, onBeforeSent });
|
|
213
|
+
});
|
|
214
|
+
const call = await waitForCall(0);
|
|
215
|
+
|
|
216
|
+
expect(onBeforeSent).toHaveBeenCalledTimes(1);
|
|
217
|
+
expect(onBeforeSent.mock.calls[0][0].requestId).toBe(call.requestId);
|
|
218
|
+
expect(onBeforeSent.mock.calls[0][0].request.payload).toStrictEqual({ name: "Maciej" });
|
|
219
|
+
});
|
|
220
|
+
it("should call the request and response lifecycle callbacks once", async () => {
|
|
221
|
+
const { createUser, waitForCall } = setup();
|
|
222
|
+
const spies = {
|
|
223
|
+
onRequestStart: vi.fn(),
|
|
224
|
+
onResponseStart: vi.fn(),
|
|
225
|
+
onResponse: vi.fn(),
|
|
226
|
+
onRemove: vi.fn(),
|
|
227
|
+
};
|
|
228
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
229
|
+
let promise: Promise<unknown> = Promise.resolve();
|
|
230
|
+
|
|
231
|
+
act(() => {
|
|
232
|
+
promise = result.current.submit({ payload: { name: "Maciej" }, ...spies });
|
|
233
|
+
});
|
|
234
|
+
const call = await waitForCall(0);
|
|
235
|
+
await act(async () => {
|
|
236
|
+
call.succeed({ id: 1, name: "Maciej" });
|
|
237
|
+
await promise;
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
expect(spies.onRequestStart).toHaveBeenCalledTimes(1);
|
|
241
|
+
expect(spies.onResponseStart).toHaveBeenCalledTimes(1);
|
|
242
|
+
expect(spies.onResponse).toHaveBeenCalledTimes(1);
|
|
243
|
+
expect(spies.onResponse.mock.calls[0][0].response.data).toStrictEqual({ id: 1, name: "Maciej" });
|
|
244
|
+
expect(spies.onRemove).not.toHaveBeenCalled();
|
|
245
|
+
});
|
|
246
|
+
it("should call the progress callbacks", async () => {
|
|
247
|
+
const { createUser, waitForCall } = setup();
|
|
248
|
+
const onUploadProgress = vi.fn();
|
|
249
|
+
const onDownloadProgress = vi.fn();
|
|
250
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
251
|
+
|
|
252
|
+
act(() => {
|
|
253
|
+
result.current.submit({ payload: { name: "Maciej" }, onUploadProgress, onDownloadProgress });
|
|
254
|
+
});
|
|
255
|
+
const call = await waitForCall(0);
|
|
256
|
+
act(() => {
|
|
257
|
+
call.upload(50, 100);
|
|
258
|
+
call.download(20, 200);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
expect(onUploadProgress).toHaveBeenCalledWith(expect.objectContaining({ loaded: 50, total: 100 }));
|
|
262
|
+
expect(onDownloadProgress).toHaveBeenCalledWith(expect.objectContaining({ loaded: 20, total: 200 }));
|
|
263
|
+
});
|
|
264
|
+
it("should call onRemove instead of onResponse when the request gets aborted", async () => {
|
|
265
|
+
const { createUser, waitForCall } = setup();
|
|
266
|
+
const onResponse = vi.fn();
|
|
267
|
+
const onRemove = vi.fn();
|
|
268
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
269
|
+
let promise: Promise<unknown> = Promise.resolve();
|
|
270
|
+
|
|
271
|
+
act(() => {
|
|
272
|
+
promise = result.current.submit({ payload: { name: "Maciej" }, onResponse, onRemove });
|
|
273
|
+
});
|
|
274
|
+
await waitForCall(0);
|
|
275
|
+
await act(async () => {
|
|
276
|
+
result.current.abort();
|
|
277
|
+
await promise;
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
expect(onRemove).toHaveBeenCalledTimes(1);
|
|
281
|
+
expect(onResponse).not.toHaveBeenCalled();
|
|
282
|
+
});
|
|
283
|
+
it("should call onResponse only with the final response of a retried request", async () => {
|
|
284
|
+
vi.useFakeTimers();
|
|
285
|
+
const { createUser, calls } = setup();
|
|
286
|
+
const onResponse = vi.fn();
|
|
287
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser.setRetry(1).setRetryTime(5000)));
|
|
288
|
+
|
|
289
|
+
act(() => {
|
|
290
|
+
result.current.submit({ payload: { name: "Maciej" }, onResponse });
|
|
291
|
+
});
|
|
292
|
+
await advance();
|
|
293
|
+
calls[0].fail();
|
|
294
|
+
await advance(5000);
|
|
295
|
+
expect(onResponse).not.toHaveBeenCalled();
|
|
296
|
+
|
|
297
|
+
calls[1].succeed({ id: 1, name: "Maciej" });
|
|
298
|
+
await advance();
|
|
299
|
+
|
|
300
|
+
expect(onResponse).toHaveBeenCalledTimes(1);
|
|
301
|
+
expect(onResponse.mock.calls[0][0].response.success).toBeTrue();
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
describe("when awaiting the promise returned by submit", () => {
|
|
306
|
+
it("should resolve with the successful response", async () => {
|
|
307
|
+
const { createUser, waitForCall } = setup();
|
|
308
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
309
|
+
let promise: ReturnType<typeof result.current.submit> | null = null;
|
|
310
|
+
|
|
311
|
+
act(() => {
|
|
312
|
+
promise = result.current.submit({ payload: { name: "Maciej" } });
|
|
313
|
+
});
|
|
314
|
+
const call = await waitForCall(0);
|
|
315
|
+
act(() => {
|
|
316
|
+
call.succeed({ id: 1, name: "Maciej" }, 201);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
await expect(promise).resolves.toStrictEqual({
|
|
320
|
+
data: { id: 1, name: "Maciej" },
|
|
321
|
+
error: null,
|
|
322
|
+
status: 201,
|
|
323
|
+
success: true,
|
|
324
|
+
extra: { headers: { "content-type": "application/json" } },
|
|
325
|
+
requestTimestamp: expect.toBeNumber(),
|
|
326
|
+
responseTimestamp: expect.toBeNumber(),
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
it("should resolve with the error response instead of rejecting", async () => {
|
|
330
|
+
const { createUser, waitForCall } = setup();
|
|
331
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
332
|
+
let promise: ReturnType<typeof result.current.submit> | null = null;
|
|
333
|
+
|
|
334
|
+
act(() => {
|
|
335
|
+
promise = result.current.submit({ payload: { name: "Maciej" } });
|
|
336
|
+
});
|
|
337
|
+
const call = await waitForCall(0);
|
|
338
|
+
act(() => {
|
|
339
|
+
call.fail({ message: "Name is taken" }, 409);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
await expect(promise).resolves.toStrictEqual({
|
|
343
|
+
data: null,
|
|
344
|
+
error: { message: "Name is taken" },
|
|
345
|
+
status: 409,
|
|
346
|
+
success: false,
|
|
347
|
+
extra: { headers: { "content-type": "application/json" } },
|
|
348
|
+
requestTimestamp: expect.toBeNumber(),
|
|
349
|
+
responseTimestamp: expect.toBeNumber(),
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
it("should resolve with an error response when the request gets aborted", async () => {
|
|
353
|
+
const { createUser, waitForCall } = setup();
|
|
354
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
355
|
+
let promise: ReturnType<typeof result.current.submit> | null = null;
|
|
356
|
+
|
|
357
|
+
act(() => {
|
|
358
|
+
promise = result.current.submit({ payload: { name: "Maciej" } });
|
|
359
|
+
});
|
|
360
|
+
await waitForCall(0);
|
|
361
|
+
act(() => {
|
|
362
|
+
result.current.abort();
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
const response = await promise!;
|
|
366
|
+
expect(response.success).toBeFalse();
|
|
367
|
+
expect(response.data).toBeNull();
|
|
368
|
+
expect(response.error).toBeInstanceOf(Error);
|
|
369
|
+
});
|
|
370
|
+
it("should resolve with the abort error when a newer cancelable submit replaces the request", async () => {
|
|
371
|
+
const { createUser, waitForCall } = setup();
|
|
372
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser.setCancelable(true)));
|
|
373
|
+
let promise: ReturnType<typeof result.current.submit> | null = null;
|
|
374
|
+
|
|
375
|
+
act(() => {
|
|
376
|
+
promise = result.current.submit({ payload: { name: "First" } });
|
|
377
|
+
});
|
|
378
|
+
await waitForCall(0);
|
|
379
|
+
act(() => {
|
|
380
|
+
result.current.submit({ payload: { name: "Second" } });
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
const response = await promise!;
|
|
384
|
+
expect(response.success).toBeFalse();
|
|
385
|
+
expect(response.error).toStrictEqual(getErrorMessage("abort"));
|
|
386
|
+
expect(response.status).toBe(0);
|
|
387
|
+
});
|
|
388
|
+
it("should resolve only once the retries are over", async () => {
|
|
389
|
+
vi.useFakeTimers();
|
|
390
|
+
const { createUser, calls } = setup();
|
|
391
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser.setRetry(1).setRetryTime(5000)));
|
|
392
|
+
const settled = vi.fn();
|
|
393
|
+
|
|
394
|
+
act(() => {
|
|
395
|
+
result.current.submit({ payload: { name: "Maciej" } }).then(settled);
|
|
396
|
+
});
|
|
397
|
+
await advance();
|
|
398
|
+
calls[0].fail({ message: "Temporary" }, 503);
|
|
399
|
+
await advance(5000);
|
|
400
|
+
expect(settled).not.toHaveBeenCalled();
|
|
401
|
+
|
|
402
|
+
calls[1].succeed({ id: 1, name: "Maciej" });
|
|
403
|
+
await advance();
|
|
404
|
+
|
|
405
|
+
expect(settled).toHaveBeenCalledTimes(1);
|
|
406
|
+
expect(settled.mock.calls[0][0].data).toStrictEqual({ id: 1, name: "Maciej" });
|
|
407
|
+
expect(settled.mock.calls[0][0].success).toBeTrue();
|
|
408
|
+
});
|
|
409
|
+
it("should resolve with the last error when every retry fails", async () => {
|
|
410
|
+
vi.useFakeTimers();
|
|
411
|
+
const { createUser, calls } = setup();
|
|
412
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser.setRetry(1).setRetryTime(5000)));
|
|
413
|
+
const settled = vi.fn();
|
|
414
|
+
|
|
415
|
+
act(() => {
|
|
416
|
+
result.current.submit({ payload: { name: "Maciej" } }).then(settled);
|
|
417
|
+
});
|
|
418
|
+
await advance();
|
|
419
|
+
calls[0].fail({ message: "First" }, 500);
|
|
420
|
+
await advance(5000);
|
|
421
|
+
calls[1].fail({ message: "Second" }, 500);
|
|
422
|
+
await advance();
|
|
423
|
+
|
|
424
|
+
expect(settled).toHaveBeenCalledTimes(1);
|
|
425
|
+
expect(settled.mock.calls[0][0].error).toStrictEqual({ message: "Second" });
|
|
426
|
+
expect(settled.mock.calls[0][0].success).toBeFalse();
|
|
427
|
+
});
|
|
428
|
+
it("should resolve even when the hook unmounted in the meantime", async () => {
|
|
429
|
+
const { createUser, waitForCall } = setup();
|
|
430
|
+
const { result, unmount } = renderHook(() => useUntrackedSubmit(createUser));
|
|
431
|
+
let promise: ReturnType<typeof result.current.submit> | null = null;
|
|
432
|
+
act(() => {
|
|
433
|
+
promise = result.current.submit({ payload: { name: "Maciej" } });
|
|
434
|
+
});
|
|
435
|
+
const call = await waitForCall(0);
|
|
436
|
+
|
|
437
|
+
unmount();
|
|
438
|
+
call.succeed({ id: 1, name: "Maciej" });
|
|
439
|
+
|
|
440
|
+
const response = await promise!;
|
|
441
|
+
expect(response.data).toStrictEqual({ id: 1, name: "Maciej" });
|
|
442
|
+
expect(response.success).toBeTrue();
|
|
443
|
+
});
|
|
444
|
+
it("should resolve with the error even when the hook unmounted in the meantime", async () => {
|
|
445
|
+
const { createUser, waitForCall } = setup();
|
|
446
|
+
const { result, unmount } = renderHook(() => useUntrackedSubmit(createUser));
|
|
447
|
+
let promise: ReturnType<typeof result.current.submit> | null = null;
|
|
448
|
+
act(() => {
|
|
449
|
+
promise = result.current.submit({ payload: { name: "Maciej" } });
|
|
450
|
+
});
|
|
451
|
+
const call = await waitForCall(0);
|
|
452
|
+
|
|
453
|
+
unmount();
|
|
454
|
+
call.fail({ message: "Nope" }, 400);
|
|
455
|
+
|
|
456
|
+
const response = await promise!;
|
|
457
|
+
expect(response.error).toStrictEqual({ message: "Nope" });
|
|
458
|
+
expect(response.success).toBeFalse();
|
|
459
|
+
});
|
|
460
|
+
it("should resolve every parallel submit with its own response", async () => {
|
|
461
|
+
const { createUser, waitForCalls } = setup();
|
|
462
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
463
|
+
let promises: ReturnType<typeof result.current.submit>[] = [];
|
|
464
|
+
|
|
465
|
+
act(() => {
|
|
466
|
+
promises = ["First", "Second", "Third"].map((name) => result.current.submit({ payload: { name } }));
|
|
467
|
+
});
|
|
468
|
+
const calls = await waitForCalls(3);
|
|
469
|
+
act(() => {
|
|
470
|
+
// Answer in a different order than the requests were sent
|
|
471
|
+
calls[2].succeed({ id: 3, name: "Third" });
|
|
472
|
+
calls[0].succeed({ id: 1, name: "First" });
|
|
473
|
+
calls[1].succeed({ id: 2, name: "Second" });
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
const responses = await Promise.all(promises);
|
|
477
|
+
expect(responses.map((response) => response.data)).toStrictEqual([
|
|
478
|
+
{ id: 1, name: "First" },
|
|
479
|
+
{ id: 2, name: "Second" },
|
|
480
|
+
{ id: 3, name: "Third" },
|
|
481
|
+
]);
|
|
482
|
+
});
|
|
483
|
+
it("should resolve the parallel submits when one of them fails", async () => {
|
|
484
|
+
const { createUser, waitForCalls } = setup();
|
|
485
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
486
|
+
let promises: ReturnType<typeof result.current.submit>[] = [];
|
|
487
|
+
|
|
488
|
+
act(() => {
|
|
489
|
+
promises = ["First", "Second"].map((name) => result.current.submit({ payload: { name } }));
|
|
490
|
+
});
|
|
491
|
+
const calls = await waitForCalls(2);
|
|
492
|
+
act(() => {
|
|
493
|
+
calls[0].fail({ message: "First failed" }, 500);
|
|
494
|
+
calls[1].succeed({ id: 2, name: "Second" });
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
const responses = await Promise.all(promises);
|
|
498
|
+
expect(responses.map((response) => response.success)).toStrictEqual([false, true]);
|
|
499
|
+
expect(responses[0].error).toStrictEqual({ message: "First failed" });
|
|
500
|
+
expect(responses[1].data).toStrictEqual({ id: 2, name: "Second" });
|
|
501
|
+
});
|
|
502
|
+
it("should allow to chain the submits one after another", async () => {
|
|
503
|
+
const { createUser, waitForCall, calls } = setup();
|
|
504
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
505
|
+
const names: string[] = [];
|
|
506
|
+
|
|
507
|
+
const chain = (async () => {
|
|
508
|
+
const first = await result.current.submit({ payload: { name: "First" } });
|
|
509
|
+
names.push(first.data?.name ?? "");
|
|
510
|
+
const second = await result.current.submit({ payload: { name: `${first.data?.name} + Second` } });
|
|
511
|
+
names.push(second.data?.name ?? "");
|
|
512
|
+
})();
|
|
513
|
+
const firstCall = await waitForCall(0);
|
|
514
|
+
expect(calls).toHaveLength(1);
|
|
515
|
+
act(() => {
|
|
516
|
+
firstCall.succeed({ id: 1, name: "First" });
|
|
517
|
+
});
|
|
518
|
+
const secondCall = await waitForCall(1);
|
|
519
|
+
act(() => {
|
|
520
|
+
secondCall.succeed({ id: 2, name: (secondCall.request.payload as { name: string }).name });
|
|
521
|
+
});
|
|
522
|
+
await act(async () => {
|
|
523
|
+
await chain;
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
expect(names).toStrictEqual(["First", "First + Second"]);
|
|
527
|
+
});
|
|
528
|
+
it("should not send the next submit of a chain when the code stops on an error", async () => {
|
|
529
|
+
const { createUser, waitForCall, calls } = setup();
|
|
530
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser));
|
|
531
|
+
|
|
532
|
+
const chain = (async () => {
|
|
533
|
+
const first = await result.current.submit({ payload: { name: "First" } });
|
|
534
|
+
if (!first.success) {
|
|
535
|
+
return "stopped";
|
|
536
|
+
}
|
|
537
|
+
await result.current.submit({ payload: { name: "Second" } });
|
|
538
|
+
return "finished";
|
|
539
|
+
})();
|
|
540
|
+
const firstCall = await waitForCall(0);
|
|
541
|
+
act(() => {
|
|
542
|
+
firstCall.fail({ message: "Nope" }, 400);
|
|
543
|
+
});
|
|
544
|
+
let outcome = "";
|
|
545
|
+
await act(async () => {
|
|
546
|
+
outcome = await chain;
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
expect(outcome).toBe("stopped");
|
|
550
|
+
expect(calls).toHaveLength(1);
|
|
551
|
+
});
|
|
552
|
+
it("should resolve with the full response when the hook selects a part of the data", async () => {
|
|
553
|
+
const { createUser, waitForCall } = setup();
|
|
554
|
+
const { result } = renderHook(() =>
|
|
555
|
+
useSubmit(createUser, { dependencyTracking: false, select: (user) => user.name }),
|
|
556
|
+
);
|
|
557
|
+
let promise: ReturnType<typeof result.current.submit> | null = null;
|
|
558
|
+
|
|
559
|
+
act(() => {
|
|
560
|
+
promise = result.current.submit({ payload: { name: "Maciej" } });
|
|
561
|
+
});
|
|
562
|
+
const call = await waitForCall(0);
|
|
563
|
+
act(() => {
|
|
564
|
+
call.succeed({ id: 1, name: "Maciej" });
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
const response = await promise!;
|
|
568
|
+
expect(response.data).toStrictEqual({ id: 1, name: "Maciej" });
|
|
569
|
+
await waitFor(() => {
|
|
570
|
+
expect(result.current.data).toBe("Maciej");
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
describe("when submit gets an empty payload", () => {
|
|
576
|
+
it("should send no payload for null instead of the payload set on the request", async () => {
|
|
577
|
+
const { client, waitForCall } = setup();
|
|
578
|
+
const request = client
|
|
579
|
+
.createRequest<{ response: User; payload: { name: string } | null }>()({ endpoint: "/users", method: "PUT" })
|
|
580
|
+
.setPayload({ name: "From request" });
|
|
581
|
+
const { result } = renderHook(() => useUntrackedSubmit(request));
|
|
582
|
+
|
|
583
|
+
act(() => {
|
|
584
|
+
result.current.submit({ payload: null });
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
const call = await waitForCall(0);
|
|
588
|
+
expect(call.request.payload).toBeUndefined();
|
|
589
|
+
});
|
|
590
|
+
it("should send the payload set on the request when submit gets none", async () => {
|
|
591
|
+
const { client, waitForCall } = setup();
|
|
592
|
+
const request = client
|
|
593
|
+
.createRequest<{ response: User; payload: { name: string } }>()({ endpoint: "/users", method: "PUT" })
|
|
594
|
+
.setPayload({ name: "From request" });
|
|
595
|
+
const { result } = renderHook(() => useUntrackedSubmit(request));
|
|
596
|
+
|
|
597
|
+
act(() => {
|
|
598
|
+
result.current.submit();
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
const call = await waitForCall(0);
|
|
602
|
+
expect(call.request.payload).toStrictEqual({ name: "From request" });
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
describe("when the hook is disabled", () => {
|
|
607
|
+
it("should not send the request", async () => {
|
|
608
|
+
vi.useFakeTimers();
|
|
609
|
+
const { createUser, calls } = setup();
|
|
610
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser, { disabled: true }));
|
|
611
|
+
|
|
612
|
+
act(() => {
|
|
613
|
+
result.current.submit({ payload: { name: "Maciej" } });
|
|
614
|
+
});
|
|
615
|
+
await advance(1000);
|
|
616
|
+
|
|
617
|
+
expect(calls).toHaveLength(0);
|
|
618
|
+
expect(result.current.submitting).toBeFalse();
|
|
619
|
+
});
|
|
620
|
+
it("should resolve right away with a complete error response", async () => {
|
|
621
|
+
const { createUser } = setup();
|
|
622
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser, { disabled: true }));
|
|
623
|
+
|
|
624
|
+
const response = await result.current.submit({ payload: { name: "Maciej" } });
|
|
625
|
+
|
|
626
|
+
expect(response).toStrictEqual({
|
|
627
|
+
data: null,
|
|
628
|
+
error: expect.any(Error),
|
|
629
|
+
status: null,
|
|
630
|
+
success: false,
|
|
631
|
+
extra: createUser.client.adapter.defaultExtra,
|
|
632
|
+
requestTimestamp: expect.toBeNumber(),
|
|
633
|
+
responseTimestamp: expect.toBeNumber(),
|
|
634
|
+
});
|
|
635
|
+
expect((response.error as Error).message).toContain("disabled");
|
|
636
|
+
});
|
|
637
|
+
it("should not change the state", async () => {
|
|
638
|
+
const { createUser } = setup();
|
|
639
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser, { disabled: true }));
|
|
640
|
+
|
|
641
|
+
await act(async () => {
|
|
642
|
+
await result.current.submit({ payload: { name: "Maciej" } });
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
expect(result.current.error).toBeNull();
|
|
646
|
+
expect(result.current.data).toBeNull();
|
|
647
|
+
expect(result.current.success).toBeFalse();
|
|
648
|
+
});
|
|
649
|
+
it("should not call the hook callbacks", async () => {
|
|
650
|
+
const { createUser } = setup();
|
|
651
|
+
const spy = vi.fn();
|
|
652
|
+
const { result } = renderHook(() => {
|
|
653
|
+
const view = useUntrackedSubmit(createUser, { disabled: true });
|
|
654
|
+
view.onSubmitRequestStart(spy);
|
|
655
|
+
view.onSubmitError(spy);
|
|
656
|
+
view.onSubmitFinished(spy);
|
|
657
|
+
return view;
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
await act(async () => {
|
|
661
|
+
await result.current.submit({ payload: { name: "Maciej" } });
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
expect(spy).not.toHaveBeenCalled();
|
|
665
|
+
});
|
|
666
|
+
it("should not call the onBeforeSent callback", async () => {
|
|
667
|
+
const { createUser } = setup();
|
|
668
|
+
const onBeforeSent = vi.fn();
|
|
669
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser, { disabled: true }));
|
|
670
|
+
|
|
671
|
+
await act(async () => {
|
|
672
|
+
await result.current.submit({ payload: { name: "Maciej" }, onBeforeSent });
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
expect(onBeforeSent).not.toHaveBeenCalled();
|
|
676
|
+
});
|
|
677
|
+
it("should send the request once the hook gets enabled", async () => {
|
|
678
|
+
const { createUser, waitForCall } = setup();
|
|
679
|
+
const { result, rerender } = renderHook(
|
|
680
|
+
({ disabled }: { disabled: boolean }) => useUntrackedSubmit(createUser, { disabled }),
|
|
681
|
+
{ initialProps: { disabled: true } },
|
|
682
|
+
);
|
|
683
|
+
|
|
684
|
+
rerender({ disabled: false });
|
|
685
|
+
act(() => {
|
|
686
|
+
result.current.submit({ payload: { name: "Maciej" } });
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
const call = await waitForCall(0);
|
|
690
|
+
expect(call.request.payload).toStrictEqual({ name: "Maciej" });
|
|
691
|
+
});
|
|
692
|
+
it("should stop sending the requests once the hook gets disabled", async () => {
|
|
693
|
+
const { createUser, calls } = setup();
|
|
694
|
+
const { result, rerender } = renderHook(
|
|
695
|
+
({ disabled }: { disabled: boolean }) => useUntrackedSubmit(createUser, { disabled }),
|
|
696
|
+
{ initialProps: { disabled: false } },
|
|
697
|
+
);
|
|
698
|
+
|
|
699
|
+
rerender({ disabled: true });
|
|
700
|
+
const response = await result.current.submit({ payload: { name: "Maciej" } });
|
|
701
|
+
|
|
702
|
+
expect(response.success).toBeFalse();
|
|
703
|
+
expect(calls).toHaveLength(0);
|
|
704
|
+
});
|
|
705
|
+
it("should take the disabled option from the provider config", async () => {
|
|
706
|
+
const { createUser, calls } = setup();
|
|
707
|
+
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
708
|
+
<Provider config={{ useSubmitConfig: { disabled: true } }}>{children}</Provider>
|
|
709
|
+
);
|
|
710
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser), { wrapper });
|
|
711
|
+
|
|
712
|
+
const response = await result.current.submit({ payload: { name: "Maciej" } });
|
|
713
|
+
|
|
714
|
+
expect(response.success).toBeFalse();
|
|
715
|
+
expect(calls).toHaveLength(0);
|
|
716
|
+
});
|
|
717
|
+
it("should prefer the hook options over the provider config", async () => {
|
|
718
|
+
const { createUser, waitForCall } = setup();
|
|
719
|
+
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
720
|
+
<Provider config={{ useSubmitConfig: { disabled: true } }}>{children}</Provider>
|
|
721
|
+
);
|
|
722
|
+
const { result } = renderHook(() => useUntrackedSubmit(createUser, { disabled: false }), { wrapper });
|
|
723
|
+
|
|
724
|
+
act(() => {
|
|
725
|
+
result.current.submit({ payload: { name: "Maciej" } });
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
const call = await waitForCall(0);
|
|
729
|
+
expect(call.request.payload).toStrictEqual({ name: "Maciej" });
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
});
|