@hyper-fetch/react 7.5.3 → 8.0.1
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/.eslintrc.cjs +12 -0
- package/__tests__/features/helpers/use-request-events/use-request-events.base.spec.ts +4 -4
- package/__tests__/features/helpers/use-request-events/use-request-events.utils.spec.ts +3 -3
- package/__tests__/features/helpers/use-socket-state/use-socket-state.base.spec.ts +44 -6
- package/__tests__/features/helpers/use-tracked-state/use-tacked-state.actions.spec.ts +177 -9
- package/__tests__/features/helpers/use-tracked-state/use-tracked-state.base.spec.ts +47 -8
- package/__tests__/features/helpers/use-tracked-state/use-tracked-state.utils.spec.ts +6 -6
- package/__tests__/features/provider/provider.hydration.spec.tsx +7 -3
- package/__tests__/features/provider/use-config-provider.base.spec.tsx +2 -1
- package/__tests__/features/use-app-manager/use-app-manager.base.spec.ts +1 -1
- package/__tests__/features/use-cache/use-cache.base.spec.ts +9 -6
- package/__tests__/features/use-cache/use-cache.helpers.ts +1 -1
- package/__tests__/features/use-cache/use-cache.typescript.spec.ts +111 -0
- package/__tests__/features/use-emitter/use-emitter.base.spec.ts +2 -2
- package/__tests__/features/use-fetch/use-fetch.base.spec.ts +103 -15
- package/__tests__/features/use-fetch/use-fetch.cancel.spec.ts +2 -2
- package/__tests__/features/use-fetch/use-fetch.clear-state.spec.ts +82 -0
- package/__tests__/features/use-fetch/use-fetch.concurrency.spec.ts +3 -3
- package/__tests__/features/use-fetch/use-fetch.debounce.spec.ts +5 -5
- package/__tests__/features/use-fetch/use-fetch.deduplication.spec.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.infinite.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.integration.spec.tsx +3 -3
- package/__tests__/features/use-fetch/use-fetch.keep-previous-data.spec.ts +215 -0
- package/__tests__/features/use-fetch/use-fetch.methods.spec.ts +34 -34
- package/__tests__/features/use-fetch/use-fetch.offline.spec.ts +3 -3
- package/__tests__/features/use-fetch/use-fetch.pagination.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.prefetch.spec.tsx +1 -1
- package/__tests__/features/use-fetch/use-fetch.refresh.spec.ts +41 -7
- package/__tests__/features/use-fetch/use-fetch.rerender.spec.tsx +2 -2
- package/__tests__/features/use-fetch/use-fetch.retry.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.revalidate.spec.ts +6 -4
- package/__tests__/features/use-fetch/use-fetch.suspense.spec.tsx +505 -0
- package/__tests__/features/use-fetch/use-fetch.typescript.spec.ts +179 -56
- package/__tests__/features/use-fetch/use-fetch.window.spec.ts +75 -3
- package/__tests__/features/use-listener/use-listener.base.spec.ts +3 -3
- package/__tests__/features/use-queue/use-queue.actions.spec.ts +1 -1
- package/__tests__/features/use-queue/use-queue.base.spec.ts +259 -1
- package/__tests__/features/use-queue/use-queue.resolve.spec.ts +173 -0
- package/__tests__/features/use-stream/use-stream.base.spec.ts +481 -0
- package/__tests__/features/use-submit/use-submit.base.spec.ts +2 -2
- package/__tests__/features/use-submit/use-submit.cancel.spec.ts +1 -1
- package/__tests__/features/use-submit/use-submit.concurrency.spec.ts +1 -1
- package/__tests__/features/use-submit/use-submit.debounce.spec.ts +8 -8
- package/__tests__/features/use-submit/use-submit.methods.spec.ts +44 -46
- package/__tests__/features/use-submit/use-submit.optimistic.spec.ts +548 -0
- package/__tests__/features/use-submit/use-submit.queue.spec.ts +3 -3
- package/__tests__/features/use-submit/use-submit.retry.spec.ts +4 -4
- package/__tests__/features/use-submit/use-submit.revalidate.spec.ts +5 -5
- package/__tests__/features/use-submit/use-submit.submit.spec.ts +4 -3
- package/__tests__/features/use-submit/use-submit.typescript.spec.ts +325 -0
- package/__tests__/shared/isolation.tests.ts +1 -1
- package/__tests__/shared/response.tests.ts +5 -4
- package/__tests__/tsconfig.json +21 -2
- package/__tests__/utils/cache.utils.ts +6 -4
- package/__tests__/utils/emitter.utils.ts +3 -2
- package/__tests__/utils/listener.utils.ts +3 -2
- package/__tests__/utils/request.utils.ts +6 -6
- package/__tests__/utils/state.utils.ts +1 -1
- package/__tests__/utils/use-app-manager.utils.ts +1 -1
- package/__tests__/utils/use-cache.utils.ts +3 -2
- package/__tests__/utils/use-emitter.utils.ts +3 -2
- package/__tests__/utils/use-fetch.utils.ts +4 -3
- package/__tests__/utils/use-listener.utils.ts +3 -2
- package/__tests__/utils/use-queue.utils.ts +4 -2
- package/__tests__/utils/use-request-events.utils.ts +3 -2
- package/__tests__/utils/use-socket-state.utils.ts +3 -2
- package/__tests__/utils/use-submit.utils.ts +3 -2
- package/__tests__/utils/use-tracked-state.utils.ts +3 -2
- package/__tests__/vitest.setup.ts +8 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/use-request-events/index.d.ts +3 -0
- package/dist/helpers/use-request-events/index.d.ts.map +1 -0
- package/dist/helpers/use-request-events/use-request-events.hooks.d.ts +10 -0
- package/dist/helpers/use-request-events/use-request-events.hooks.d.ts.map +1 -0
- package/dist/helpers/use-request-events/use-request-events.types.d.ts +78 -0
- package/dist/helpers/use-request-events/use-request-events.types.d.ts.map +1 -0
- package/dist/helpers/use-socket-state/index.d.ts +4 -0
- package/dist/helpers/use-socket-state/index.d.ts.map +1 -0
- package/dist/helpers/use-socket-state/use-socket-state.constants.d.ts +4 -0
- package/dist/helpers/use-socket-state/use-socket-state.constants.d.ts.map +1 -0
- package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts +24 -0
- package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts.map +1 -0
- package/dist/helpers/use-socket-state/use-socket-state.types.d.ts +12 -0
- package/dist/helpers/use-socket-state/use-socket-state.types.d.ts.map +1 -0
- package/dist/helpers/use-tracked-state/index.d.ts +5 -0
- package/dist/helpers/use-tracked-state/index.d.ts.map +1 -0
- package/dist/helpers/use-tracked-state/use-tracked-state.constants.d.ts +3 -0
- package/dist/helpers/use-tracked-state/use-tracked-state.constants.d.ts.map +1 -0
- package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts +12 -0
- package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts.map +1 -0
- package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts +113 -0
- package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts.map +1 -0
- package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts +29 -0
- package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts.map +1 -0
- package/dist/hooks/use-app-manager/index.d.ts +3 -0
- package/dist/hooks/use-app-manager/index.d.ts.map +1 -0
- package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +4 -0
- package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts.map +1 -0
- package/dist/hooks/use-app-manager/use-app-manager.types.d.ts +19 -0
- package/dist/hooks/use-app-manager/use-app-manager.types.d.ts.map +1 -0
- package/dist/hooks/use-cache/index.d.ts +4 -0
- package/dist/hooks/use-cache/index.d.ts.map +1 -0
- package/dist/hooks/use-cache/use-cache.constants.d.ts +6 -0
- package/dist/hooks/use-cache/use-cache.constants.d.ts.map +1 -0
- package/dist/hooks/use-cache/use-cache.hooks.d.ts +4 -0
- package/dist/hooks/use-cache/use-cache.hooks.d.ts.map +1 -0
- package/dist/hooks/use-cache/use-cache.types.d.ts +24 -0
- package/dist/hooks/use-cache/use-cache.types.d.ts.map +1 -0
- package/dist/hooks/use-emitter/index.d.ts +3 -0
- package/dist/hooks/use-emitter/index.d.ts.map +1 -0
- package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +26 -0
- package/dist/hooks/use-emitter/use-emitter.hooks.d.ts.map +1 -0
- package/dist/hooks/use-emitter/use-emitter.types.d.ts +4 -0
- package/dist/hooks/use-emitter/use-emitter.types.d.ts.map +1 -0
- package/dist/hooks/use-fetch/index.d.ts +5 -0
- package/dist/hooks/use-fetch/index.d.ts.map +1 -0
- package/dist/hooks/use-fetch/use-fetch.constants.d.ts +8 -0
- package/dist/hooks/use-fetch/use-fetch.constants.d.ts.map +1 -0
- package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +10 -0
- package/dist/hooks/use-fetch/use-fetch.hooks.d.ts.map +1 -0
- package/dist/hooks/use-fetch/use-fetch.types.d.ts +118 -0
- package/dist/hooks/use-fetch/use-fetch.types.d.ts.map +1 -0
- package/dist/hooks/use-fetch/use-fetch.utils.d.ts +2 -0
- package/dist/hooks/use-fetch/use-fetch.utils.d.ts.map +1 -0
- package/dist/hooks/use-listener/index.d.ts +3 -0
- package/dist/hooks/use-listener/index.d.ts.map +1 -0
- package/dist/hooks/use-listener/use-listener.hooks.d.ts +31 -0
- package/dist/hooks/use-listener/use-listener.hooks.d.ts.map +1 -0
- package/dist/hooks/use-listener/use-listener.types.d.ts +4 -0
- package/dist/hooks/use-listener/use-listener.types.d.ts.map +1 -0
- package/dist/hooks/use-queue/index.d.ts +4 -0
- package/dist/hooks/use-queue/index.d.ts.map +1 -0
- package/dist/hooks/use-queue/use-queue.constants.d.ts +4 -0
- package/dist/hooks/use-queue/use-queue.constants.d.ts.map +1 -0
- package/dist/hooks/use-queue/use-queue.hooks.d.ts +10 -0
- package/dist/hooks/use-queue/use-queue.hooks.d.ts.map +1 -0
- package/dist/hooks/use-queue/use-queue.types.d.ts +58 -0
- package/dist/hooks/use-queue/use-queue.types.d.ts.map +1 -0
- package/dist/hooks/use-stream/index.d.ts +3 -0
- package/dist/hooks/use-stream/index.d.ts.map +1 -0
- package/dist/hooks/use-stream/use-stream.hooks.d.ts +11 -0
- package/dist/hooks/use-stream/use-stream.hooks.d.ts.map +1 -0
- package/dist/hooks/use-stream/use-stream.types.d.ts +52 -0
- package/dist/hooks/use-stream/use-stream.types.d.ts.map +1 -0
- package/dist/hooks/use-submit/index.d.ts +4 -0
- package/dist/hooks/use-submit/index.d.ts.map +1 -0
- package/dist/hooks/use-submit/use-submit.constants.d.ts +8 -0
- package/dist/hooks/use-submit/use-submit.constants.d.ts.map +1 -0
- package/dist/hooks/use-submit/use-submit.hooks.d.ts +10 -0
- package/dist/hooks/use-submit/use-submit.hooks.d.ts.map +1 -0
- package/dist/hooks/use-submit/use-submit.types.d.ts +115 -0
- package/dist/hooks/use-submit/use-submit.types.d.ts.map +1 -0
- package/dist/index.d.ts +12 -733
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +1935 -0
- package/dist/index.mjs.map +1 -0
- package/dist/provider/index.d.ts +3 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/provider.d.ts +13 -0
- package/dist/provider/provider.d.ts.map +1 -0
- package/dist/provider/provider.types.d.ts +31 -0
- package/dist/provider/provider.types.d.ts.map +1 -0
- package/dist/utils/bounce.utils.d.ts +8 -0
- package/dist/utils/bounce.utils.d.ts.map +1 -0
- package/dist/utils/deep-equal.utils.d.ts +14 -0
- package/dist/utils/deep-equal.utils.d.ts.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/tracked-proxy.utils.d.ts +7 -0
- package/dist/utils/tracked-proxy.utils.d.ts.map +1 -0
- package/package.json +21 -13
- package/src/helpers/use-request-events/use-request-events.hooks.ts +60 -14
- package/src/helpers/use-request-events/use-request-events.types.ts +19 -12
- package/src/helpers/use-socket-state/use-socket-state.constants.ts +2 -2
- package/src/helpers/use-socket-state/use-socket-state.hooks.ts +47 -13
- package/src/helpers/use-socket-state/use-socket-state.types.ts +1 -1
- package/src/helpers/use-tracked-state/use-tracked-state.constants.ts +1 -1
- package/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +74 -22
- package/src/helpers/use-tracked-state/use-tracked-state.types.ts +7 -2
- package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +39 -4
- package/src/hooks/use-app-manager/use-app-manager.hooks.ts +2 -2
- package/src/hooks/use-cache/use-cache.hooks.ts +33 -41
- package/src/hooks/use-cache/use-cache.types.ts +3 -3
- package/src/hooks/use-emitter/use-emitter.hooks.ts +17 -16
- package/src/hooks/use-fetch/use-fetch.constants.ts +5 -2
- package/src/hooks/use-fetch/use-fetch.hooks.ts +109 -51
- package/src/hooks/use-fetch/use-fetch.types.ts +18 -3
- package/src/hooks/use-listener/use-listener.hooks.ts +19 -27
- package/src/hooks/use-queue/use-queue.constants.ts +2 -2
- package/src/hooks/use-queue/use-queue.hooks.ts +25 -6
- package/src/hooks/use-queue/use-queue.types.ts +8 -2
- package/src/hooks/use-stream/index.ts +2 -0
- package/src/hooks/use-stream/use-stream.hooks.ts +164 -0
- package/src/hooks/use-stream/use-stream.types.ts +53 -0
- package/src/hooks/use-submit/use-submit.constants.ts +2 -2
- package/src/hooks/use-submit/use-submit.hooks.ts +43 -48
- package/src/hooks/use-submit/use-submit.types.ts +9 -9
- package/src/index.ts +1 -0
- package/src/provider/provider.tsx +1 -1
- package/src/provider/provider.types.ts +8 -8
- package/src/utils/index.ts +1 -0
- package/src/utils/tracked-proxy.utils.ts +19 -0
- package/tsconfig.json +1 -1
- package/vite.config.ts +45 -0
- package/.eslintrc.json +0 -11
- package/__tests__/features/use-fetch/use-fetch.suspense.ts +0 -37
- package/__tests__/global.d.ts +0 -1
- package/__tests__/jest.setup.ts +0 -9
- package/dist/index.js +0 -1541
- package/dist/index.js.map +0 -7
- package/jest.config.ts +0 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RequestInstance, ExtractAdapterResolvedType } from "@hyper-fetch/core";
|
|
1
|
+
import type { RequestInstance, ExtractAdapterResolvedType } from "@hyper-fetch/core";
|
|
2
2
|
import { act, waitFor } from "@testing-library/react";
|
|
3
3
|
import { createHttpMockingServer } from "@hyper-fetch/testing";
|
|
4
4
|
|
|
@@ -25,7 +25,7 @@ describe("useSubmit [ Bounce ]", () => {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
beforeEach(() => {
|
|
28
|
-
|
|
28
|
+
vi.resetModules();
|
|
29
29
|
client.clear();
|
|
30
30
|
request = createRequest({ method: "POST" });
|
|
31
31
|
});
|
|
@@ -53,7 +53,7 @@ describe("useSubmit [ Bounce ]", () => {
|
|
|
53
53
|
expect((startTime || 0) - (submitTime || 0)).toBeGreaterThanOrEqual(hookDebounceOptions.bounceTime);
|
|
54
54
|
});
|
|
55
55
|
it("should debounce multiple request triggers by bounceTime", async () => {
|
|
56
|
-
const spy =
|
|
56
|
+
const spy = vi.fn();
|
|
57
57
|
let submitTime: number | null = null;
|
|
58
58
|
let startTime: number | null = null;
|
|
59
59
|
mockRequest(request);
|
|
@@ -107,7 +107,7 @@ describe("useSubmit [ Bounce ]", () => {
|
|
|
107
107
|
});
|
|
108
108
|
it("should change debounce time", async () => {
|
|
109
109
|
const newBounceTime = 200;
|
|
110
|
-
const spy =
|
|
110
|
+
const spy = vi.fn();
|
|
111
111
|
let submitTime: number | null = null;
|
|
112
112
|
let startTime: number | null = null;
|
|
113
113
|
mockRequest(request);
|
|
@@ -147,7 +147,7 @@ describe("useSubmit [ Bounce ]", () => {
|
|
|
147
147
|
describe("given debounce is off", () => {
|
|
148
148
|
describe("when request is about to change", () => {
|
|
149
149
|
it("should not debounce multiple request triggers", async () => {
|
|
150
|
-
const spy =
|
|
150
|
+
const spy = vi.fn();
|
|
151
151
|
let startTime: number | null = null;
|
|
152
152
|
mockRequest(request, { delay: 0 });
|
|
153
153
|
const response = renderUseSubmit(request);
|
|
@@ -198,7 +198,7 @@ describe("useSubmit [ Bounce ]", () => {
|
|
|
198
198
|
});
|
|
199
199
|
});
|
|
200
200
|
it("should throttle multiple request triggers by bounceTime", async () => {
|
|
201
|
-
const spy =
|
|
201
|
+
const spy = vi.fn();
|
|
202
202
|
let submitTime: number | null = null;
|
|
203
203
|
let startTime: number | null = null;
|
|
204
204
|
mockRequest(request);
|
|
@@ -251,7 +251,7 @@ describe("useSubmit [ Bounce ]", () => {
|
|
|
251
251
|
});
|
|
252
252
|
it("should change throttle time", async () => {
|
|
253
253
|
const newBounceTime = 200;
|
|
254
|
-
const spy =
|
|
254
|
+
const spy = vi.fn();
|
|
255
255
|
let submitTime: number | null = null;
|
|
256
256
|
let startTime: number | null = null;
|
|
257
257
|
mockRequest(request);
|
|
@@ -290,7 +290,7 @@ describe("useSubmit [ Bounce ]", () => {
|
|
|
290
290
|
describe("given throttle is off", () => {
|
|
291
291
|
describe("when request is about to change", () => {
|
|
292
292
|
it("should not throttle multiple request triggers", async () => {
|
|
293
|
-
const spy =
|
|
293
|
+
const spy = vi.fn();
|
|
294
294
|
let startTime: number | null = null;
|
|
295
295
|
mockRequest(request, { delay: 0 });
|
|
296
296
|
const response = renderUseSubmit(request);
|
|
@@ -7,9 +7,7 @@ import { client, createRequest, renderUseSubmit } from "../../utils";
|
|
|
7
7
|
const { resetMocks, startServer, stopServer, mockRequest } = createHttpMockingServer();
|
|
8
8
|
|
|
9
9
|
describe("useSubmit [ Methods ]", () => {
|
|
10
|
-
let request = createRequest
|
|
11
|
-
queryParams?: string;
|
|
12
|
-
}>({ method: "POST" });
|
|
10
|
+
let request = createRequest({ method: "POST" });
|
|
13
11
|
|
|
14
12
|
beforeAll(() => {
|
|
15
13
|
startServer();
|
|
@@ -24,15 +22,15 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
24
22
|
});
|
|
25
23
|
|
|
26
24
|
beforeEach(() => {
|
|
27
|
-
|
|
28
|
-
request = createRequest
|
|
25
|
+
vi.resetModules();
|
|
26
|
+
request = createRequest({ method: "POST" });
|
|
29
27
|
client.clear();
|
|
30
28
|
});
|
|
31
29
|
|
|
32
30
|
describe("given hook is mounted", () => {
|
|
33
31
|
describe("when processing request", () => {
|
|
34
32
|
it("should trigger onRequestStart helper", async () => {
|
|
35
|
-
const spy =
|
|
33
|
+
const spy = vi.fn();
|
|
36
34
|
const mock = mockRequest(request);
|
|
37
35
|
const response = renderUseSubmit(request);
|
|
38
36
|
|
|
@@ -45,7 +43,7 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
45
43
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
46
44
|
});
|
|
47
45
|
it("should trigger onResponseStart helper", async () => {
|
|
48
|
-
const spy =
|
|
46
|
+
const spy = vi.fn();
|
|
49
47
|
const mock = mockRequest(request);
|
|
50
48
|
const response = renderUseSubmit(request);
|
|
51
49
|
|
|
@@ -58,7 +56,7 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
58
56
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
59
57
|
});
|
|
60
58
|
it("should trigger onDownloadProgress helper", async () => {
|
|
61
|
-
const spy =
|
|
59
|
+
const spy = vi.fn();
|
|
62
60
|
const mock = mockRequest(request);
|
|
63
61
|
const response = renderUseSubmit(request);
|
|
64
62
|
|
|
@@ -68,10 +66,10 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
68
66
|
});
|
|
69
67
|
|
|
70
68
|
await testSuccessState(mock, response);
|
|
71
|
-
expect(spy).
|
|
69
|
+
expect(spy.mock.calls.length).toBeGreaterThanOrEqual(1);
|
|
72
70
|
});
|
|
73
71
|
it("should trigger onUploadProgress helper", async () => {
|
|
74
|
-
const spy =
|
|
72
|
+
const spy = vi.fn();
|
|
75
73
|
const mock = mockRequest(request);
|
|
76
74
|
const response = renderUseSubmit(request);
|
|
77
75
|
|
|
@@ -81,15 +79,15 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
81
79
|
});
|
|
82
80
|
|
|
83
81
|
await testSuccessState(mock, response);
|
|
84
|
-
expect(spy).
|
|
82
|
+
expect(spy.mock.calls.length).toBeGreaterThanOrEqual(1);
|
|
85
83
|
});
|
|
86
84
|
it("should allow to trigger all event methods on dynamic keys change", async () => {
|
|
87
|
-
const spy1 =
|
|
88
|
-
const spy2 =
|
|
89
|
-
const spy3 =
|
|
90
|
-
const spy4 =
|
|
91
|
-
const spy5 =
|
|
92
|
-
const spy6 =
|
|
85
|
+
const spy1 = vi.fn();
|
|
86
|
+
const spy2 = vi.fn();
|
|
87
|
+
const spy3 = vi.fn();
|
|
88
|
+
const spy4 = vi.fn();
|
|
89
|
+
const spy5 = vi.fn();
|
|
90
|
+
const spy6 = vi.fn();
|
|
93
91
|
const mock = mockRequest(request);
|
|
94
92
|
const response = renderUseSubmit(request);
|
|
95
93
|
|
|
@@ -108,16 +106,16 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
108
106
|
await testSuccessState(mock, response);
|
|
109
107
|
expect(spy1).toHaveBeenCalledTimes(3);
|
|
110
108
|
expect(spy2).toHaveBeenCalledTimes(3);
|
|
111
|
-
expect(spy3).
|
|
112
|
-
expect(spy4).
|
|
109
|
+
expect(spy3.mock.calls.length).toBeGreaterThanOrEqual(3);
|
|
110
|
+
expect(spy4.mock.calls.length).toBeGreaterThanOrEqual(3);
|
|
113
111
|
expect(spy5).toHaveBeenCalledTimes(3);
|
|
114
112
|
expect(spy6).toHaveBeenCalledTimes(3);
|
|
115
113
|
});
|
|
116
114
|
});
|
|
117
115
|
describe("when getting the response", () => {
|
|
118
116
|
it("should trigger onSuccess helper", async () => {
|
|
119
|
-
const spy =
|
|
120
|
-
const unusedSpy =
|
|
117
|
+
const spy = vi.fn();
|
|
118
|
+
const unusedSpy = vi.fn();
|
|
121
119
|
const mock = mockRequest(request);
|
|
122
120
|
const response = renderUseSubmit(request);
|
|
123
121
|
|
|
@@ -132,8 +130,8 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
132
130
|
expect(unusedSpy).toHaveBeenCalledTimes(0);
|
|
133
131
|
});
|
|
134
132
|
it("should trigger onError helper", async () => {
|
|
135
|
-
const spy =
|
|
136
|
-
const unusedSpy =
|
|
133
|
+
const spy = vi.fn();
|
|
134
|
+
const unusedSpy = vi.fn();
|
|
137
135
|
const mock = mockRequest(request, { status: 400 });
|
|
138
136
|
const response = renderUseSubmit(request);
|
|
139
137
|
|
|
@@ -148,7 +146,7 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
148
146
|
expect(unusedSpy).toHaveBeenCalledTimes(0);
|
|
149
147
|
});
|
|
150
148
|
it("should trigger onFinished helper on success", async () => {
|
|
151
|
-
const spy =
|
|
149
|
+
const spy = vi.fn();
|
|
152
150
|
const mock = mockRequest(request);
|
|
153
151
|
const response = renderUseSubmit(request);
|
|
154
152
|
|
|
@@ -161,7 +159,7 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
161
159
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
162
160
|
});
|
|
163
161
|
it("should trigger onFinished helper on error", async () => {
|
|
164
|
-
const spy =
|
|
162
|
+
const spy = vi.fn();
|
|
165
163
|
const mock = mockRequest(request, { status: 400 });
|
|
166
164
|
const response = renderUseSubmit(request);
|
|
167
165
|
|
|
@@ -176,7 +174,7 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
176
174
|
});
|
|
177
175
|
describe("when getting internal error", () => {
|
|
178
176
|
it("should trigger onOfflineError helper", async () => {
|
|
179
|
-
const spy =
|
|
177
|
+
const spy = vi.fn();
|
|
180
178
|
mockRequest(request, { status: 400 });
|
|
181
179
|
const response = renderUseSubmit(request.setOffline(true));
|
|
182
180
|
|
|
@@ -192,14 +190,14 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
192
190
|
});
|
|
193
191
|
|
|
194
192
|
it("should trigger methods on retry", async () => {
|
|
195
|
-
const spy1 =
|
|
196
|
-
const spy2 =
|
|
197
|
-
const spy3 =
|
|
198
|
-
const spy4 =
|
|
199
|
-
const spy5 =
|
|
200
|
-
const spy6 =
|
|
201
|
-
const spy7 =
|
|
202
|
-
const spy8 =
|
|
193
|
+
const spy1 = vi.fn();
|
|
194
|
+
const spy2 = vi.fn();
|
|
195
|
+
const spy3 = vi.fn();
|
|
196
|
+
const spy4 = vi.fn();
|
|
197
|
+
const spy5 = vi.fn();
|
|
198
|
+
const spy6 = vi.fn();
|
|
199
|
+
const spy7 = vi.fn();
|
|
200
|
+
const spy8 = vi.fn();
|
|
203
201
|
|
|
204
202
|
const errorMock = mockRequest(request, { status: 400 });
|
|
205
203
|
const response = renderUseSubmit(request.setRetry(1).setRetryTime(100));
|
|
@@ -222,22 +220,22 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
222
220
|
|
|
223
221
|
expect(spy1).toHaveBeenCalledTimes(2);
|
|
224
222
|
expect(spy2).toHaveBeenCalledTimes(2);
|
|
225
|
-
expect(spy3).
|
|
226
|
-
expect(spy4).
|
|
223
|
+
expect(spy3.mock.calls.length).toBeGreaterThanOrEqual(2);
|
|
224
|
+
expect(spy4.mock.calls.length).toBeGreaterThanOrEqual(2);
|
|
227
225
|
expect(spy5).toHaveBeenCalledTimes(1);
|
|
228
226
|
expect(spy6).toHaveBeenCalledTimes(1);
|
|
229
227
|
expect(spy7).toHaveBeenCalledTimes(2);
|
|
230
228
|
expect(spy8).toHaveBeenCalledTimes(0);
|
|
231
229
|
});
|
|
232
230
|
it("should trigger methods on coming back online", async () => {
|
|
233
|
-
const spy1 =
|
|
234
|
-
const spy2 =
|
|
235
|
-
const spy3 =
|
|
236
|
-
const spy4 =
|
|
237
|
-
const spy5 =
|
|
238
|
-
const spy6 =
|
|
239
|
-
const spy7 =
|
|
240
|
-
const spy8 =
|
|
231
|
+
const spy1 = vi.fn();
|
|
232
|
+
const spy2 = vi.fn();
|
|
233
|
+
const spy3 = vi.fn();
|
|
234
|
+
const spy4 = vi.fn();
|
|
235
|
+
const spy5 = vi.fn();
|
|
236
|
+
const spy6 = vi.fn();
|
|
237
|
+
const spy7 = vi.fn();
|
|
238
|
+
const spy8 = vi.fn();
|
|
241
239
|
|
|
242
240
|
const errorMock = mockRequest(request, { status: 400 });
|
|
243
241
|
const response = renderUseSubmit(request);
|
|
@@ -266,8 +264,8 @@ describe("useSubmit [ Methods ]", () => {
|
|
|
266
264
|
await testSuccessState(successMock, response);
|
|
267
265
|
expect(spy1).toHaveBeenCalledTimes(2);
|
|
268
266
|
expect(spy2).toHaveBeenCalledTimes(2);
|
|
269
|
-
expect(spy3).
|
|
270
|
-
expect(spy4).
|
|
267
|
+
expect(spy3.mock.calls.length).toBeGreaterThanOrEqual(2);
|
|
268
|
+
expect(spy4.mock.calls.length).toBeGreaterThanOrEqual(2);
|
|
271
269
|
expect(spy5).toHaveBeenCalledTimes(1);
|
|
272
270
|
expect(spy6).toHaveBeenCalledTimes(0);
|
|
273
271
|
expect(spy7).toHaveBeenCalledTimes(2);
|