@hyper-fetch/react 7.5.3 → 8.0.0

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 (212) hide show
  1. package/.eslintrc.cjs +12 -0
  2. package/__tests__/features/helpers/use-request-events/use-request-events.base.spec.ts +4 -4
  3. package/__tests__/features/helpers/use-request-events/use-request-events.utils.spec.ts +3 -3
  4. package/__tests__/features/helpers/use-socket-state/use-socket-state.base.spec.ts +44 -6
  5. package/__tests__/features/helpers/use-tracked-state/use-tacked-state.actions.spec.ts +177 -9
  6. package/__tests__/features/helpers/use-tracked-state/use-tracked-state.base.spec.ts +47 -8
  7. package/__tests__/features/helpers/use-tracked-state/use-tracked-state.utils.spec.ts +6 -6
  8. package/__tests__/features/provider/provider.hydration.spec.tsx +7 -3
  9. package/__tests__/features/provider/use-config-provider.base.spec.tsx +2 -1
  10. package/__tests__/features/use-app-manager/use-app-manager.base.spec.ts +1 -1
  11. package/__tests__/features/use-cache/use-cache.base.spec.ts +9 -6
  12. package/__tests__/features/use-cache/use-cache.helpers.ts +1 -1
  13. package/__tests__/features/use-cache/use-cache.typescript.spec.ts +111 -0
  14. package/__tests__/features/use-emitter/use-emitter.base.spec.ts +2 -2
  15. package/__tests__/features/use-fetch/use-fetch.base.spec.ts +103 -15
  16. package/__tests__/features/use-fetch/use-fetch.cancel.spec.ts +2 -2
  17. package/__tests__/features/use-fetch/use-fetch.clear-state.spec.ts +82 -0
  18. package/__tests__/features/use-fetch/use-fetch.concurrency.spec.ts +3 -3
  19. package/__tests__/features/use-fetch/use-fetch.debounce.spec.ts +5 -5
  20. package/__tests__/features/use-fetch/use-fetch.deduplication.spec.ts +1 -1
  21. package/__tests__/features/use-fetch/use-fetch.infinite.ts +1 -1
  22. package/__tests__/features/use-fetch/use-fetch.integration.spec.tsx +3 -3
  23. package/__tests__/features/use-fetch/use-fetch.keep-previous-data.spec.ts +215 -0
  24. package/__tests__/features/use-fetch/use-fetch.methods.spec.ts +34 -34
  25. package/__tests__/features/use-fetch/use-fetch.offline.spec.ts +3 -3
  26. package/__tests__/features/use-fetch/use-fetch.pagination.ts +1 -1
  27. package/__tests__/features/use-fetch/use-fetch.prefetch.spec.tsx +1 -1
  28. package/__tests__/features/use-fetch/use-fetch.refresh.spec.ts +41 -7
  29. package/__tests__/features/use-fetch/use-fetch.rerender.spec.tsx +2 -2
  30. package/__tests__/features/use-fetch/use-fetch.retry.ts +1 -1
  31. package/__tests__/features/use-fetch/use-fetch.revalidate.spec.ts +6 -4
  32. package/__tests__/features/use-fetch/use-fetch.suspense.spec.tsx +505 -0
  33. package/__tests__/features/use-fetch/use-fetch.typescript.spec.ts +179 -56
  34. package/__tests__/features/use-fetch/use-fetch.window.spec.ts +75 -3
  35. package/__tests__/features/use-listener/use-listener.base.spec.ts +3 -3
  36. package/__tests__/features/use-queue/use-queue.actions.spec.ts +1 -1
  37. package/__tests__/features/use-queue/use-queue.base.spec.ts +259 -1
  38. package/__tests__/features/use-queue/use-queue.resolve.spec.ts +173 -0
  39. package/__tests__/features/use-stream/use-stream.base.spec.ts +481 -0
  40. package/__tests__/features/use-submit/use-submit.base.spec.ts +2 -2
  41. package/__tests__/features/use-submit/use-submit.cancel.spec.ts +1 -1
  42. package/__tests__/features/use-submit/use-submit.concurrency.spec.ts +1 -1
  43. package/__tests__/features/use-submit/use-submit.debounce.spec.ts +8 -8
  44. package/__tests__/features/use-submit/use-submit.methods.spec.ts +44 -46
  45. package/__tests__/features/use-submit/use-submit.optimistic.spec.ts +548 -0
  46. package/__tests__/features/use-submit/use-submit.queue.spec.ts +3 -3
  47. package/__tests__/features/use-submit/use-submit.retry.spec.ts +4 -4
  48. package/__tests__/features/use-submit/use-submit.revalidate.spec.ts +5 -5
  49. package/__tests__/features/use-submit/use-submit.submit.spec.ts +4 -3
  50. package/__tests__/features/use-submit/use-submit.typescript.spec.ts +325 -0
  51. package/__tests__/shared/isolation.tests.ts +1 -1
  52. package/__tests__/shared/response.tests.ts +5 -4
  53. package/__tests__/tsconfig.json +21 -2
  54. package/__tests__/utils/cache.utils.ts +6 -4
  55. package/__tests__/utils/emitter.utils.ts +3 -2
  56. package/__tests__/utils/listener.utils.ts +3 -2
  57. package/__tests__/utils/request.utils.ts +6 -6
  58. package/__tests__/utils/state.utils.ts +1 -1
  59. package/__tests__/utils/use-app-manager.utils.ts +1 -1
  60. package/__tests__/utils/use-cache.utils.ts +3 -2
  61. package/__tests__/utils/use-emitter.utils.ts +3 -2
  62. package/__tests__/utils/use-fetch.utils.ts +4 -3
  63. package/__tests__/utils/use-listener.utils.ts +3 -2
  64. package/__tests__/utils/use-queue.utils.ts +4 -2
  65. package/__tests__/utils/use-request-events.utils.ts +3 -2
  66. package/__tests__/utils/use-socket-state.utils.ts +3 -2
  67. package/__tests__/utils/use-submit.utils.ts +3 -2
  68. package/__tests__/utils/use-tracked-state.utils.ts +3 -2
  69. package/__tests__/vitest.setup.ts +8 -0
  70. package/dist/helpers/index.d.ts +4 -0
  71. package/dist/helpers/index.d.ts.map +1 -0
  72. package/dist/helpers/use-request-events/index.d.ts +3 -0
  73. package/dist/helpers/use-request-events/index.d.ts.map +1 -0
  74. package/dist/helpers/use-request-events/use-request-events.hooks.d.ts +10 -0
  75. package/dist/helpers/use-request-events/use-request-events.hooks.d.ts.map +1 -0
  76. package/dist/helpers/use-request-events/use-request-events.types.d.ts +78 -0
  77. package/dist/helpers/use-request-events/use-request-events.types.d.ts.map +1 -0
  78. package/dist/helpers/use-socket-state/index.d.ts +4 -0
  79. package/dist/helpers/use-socket-state/index.d.ts.map +1 -0
  80. package/dist/helpers/use-socket-state/use-socket-state.constants.d.ts +4 -0
  81. package/dist/helpers/use-socket-state/use-socket-state.constants.d.ts.map +1 -0
  82. package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts +24 -0
  83. package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts.map +1 -0
  84. package/dist/helpers/use-socket-state/use-socket-state.types.d.ts +12 -0
  85. package/dist/helpers/use-socket-state/use-socket-state.types.d.ts.map +1 -0
  86. package/dist/helpers/use-tracked-state/index.d.ts +5 -0
  87. package/dist/helpers/use-tracked-state/index.d.ts.map +1 -0
  88. package/dist/helpers/use-tracked-state/use-tracked-state.constants.d.ts +3 -0
  89. package/dist/helpers/use-tracked-state/use-tracked-state.constants.d.ts.map +1 -0
  90. package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts +12 -0
  91. package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts.map +1 -0
  92. package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts +113 -0
  93. package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts.map +1 -0
  94. package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts +29 -0
  95. package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts.map +1 -0
  96. package/dist/hooks/use-app-manager/index.d.ts +3 -0
  97. package/dist/hooks/use-app-manager/index.d.ts.map +1 -0
  98. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +4 -0
  99. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts.map +1 -0
  100. package/dist/hooks/use-app-manager/use-app-manager.types.d.ts +19 -0
  101. package/dist/hooks/use-app-manager/use-app-manager.types.d.ts.map +1 -0
  102. package/dist/hooks/use-cache/index.d.ts +4 -0
  103. package/dist/hooks/use-cache/index.d.ts.map +1 -0
  104. package/dist/hooks/use-cache/use-cache.constants.d.ts +6 -0
  105. package/dist/hooks/use-cache/use-cache.constants.d.ts.map +1 -0
  106. package/dist/hooks/use-cache/use-cache.hooks.d.ts +4 -0
  107. package/dist/hooks/use-cache/use-cache.hooks.d.ts.map +1 -0
  108. package/dist/hooks/use-cache/use-cache.types.d.ts +24 -0
  109. package/dist/hooks/use-cache/use-cache.types.d.ts.map +1 -0
  110. package/dist/hooks/use-emitter/index.d.ts +3 -0
  111. package/dist/hooks/use-emitter/index.d.ts.map +1 -0
  112. package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +26 -0
  113. package/dist/hooks/use-emitter/use-emitter.hooks.d.ts.map +1 -0
  114. package/dist/hooks/use-emitter/use-emitter.types.d.ts +4 -0
  115. package/dist/hooks/use-emitter/use-emitter.types.d.ts.map +1 -0
  116. package/dist/hooks/use-fetch/index.d.ts +5 -0
  117. package/dist/hooks/use-fetch/index.d.ts.map +1 -0
  118. package/dist/hooks/use-fetch/use-fetch.constants.d.ts +8 -0
  119. package/dist/hooks/use-fetch/use-fetch.constants.d.ts.map +1 -0
  120. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +10 -0
  121. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts.map +1 -0
  122. package/dist/hooks/use-fetch/use-fetch.types.d.ts +118 -0
  123. package/dist/hooks/use-fetch/use-fetch.types.d.ts.map +1 -0
  124. package/dist/hooks/use-fetch/use-fetch.utils.d.ts +2 -0
  125. package/dist/hooks/use-fetch/use-fetch.utils.d.ts.map +1 -0
  126. package/dist/hooks/use-listener/index.d.ts +3 -0
  127. package/dist/hooks/use-listener/index.d.ts.map +1 -0
  128. package/dist/hooks/use-listener/use-listener.hooks.d.ts +31 -0
  129. package/dist/hooks/use-listener/use-listener.hooks.d.ts.map +1 -0
  130. package/dist/hooks/use-listener/use-listener.types.d.ts +4 -0
  131. package/dist/hooks/use-listener/use-listener.types.d.ts.map +1 -0
  132. package/dist/hooks/use-queue/index.d.ts +4 -0
  133. package/dist/hooks/use-queue/index.d.ts.map +1 -0
  134. package/dist/hooks/use-queue/use-queue.constants.d.ts +4 -0
  135. package/dist/hooks/use-queue/use-queue.constants.d.ts.map +1 -0
  136. package/dist/hooks/use-queue/use-queue.hooks.d.ts +10 -0
  137. package/dist/hooks/use-queue/use-queue.hooks.d.ts.map +1 -0
  138. package/dist/hooks/use-queue/use-queue.types.d.ts +58 -0
  139. package/dist/hooks/use-queue/use-queue.types.d.ts.map +1 -0
  140. package/dist/hooks/use-stream/index.d.ts +3 -0
  141. package/dist/hooks/use-stream/index.d.ts.map +1 -0
  142. package/dist/hooks/use-stream/use-stream.hooks.d.ts +11 -0
  143. package/dist/hooks/use-stream/use-stream.hooks.d.ts.map +1 -0
  144. package/dist/hooks/use-stream/use-stream.types.d.ts +52 -0
  145. package/dist/hooks/use-stream/use-stream.types.d.ts.map +1 -0
  146. package/dist/hooks/use-submit/index.d.ts +4 -0
  147. package/dist/hooks/use-submit/index.d.ts.map +1 -0
  148. package/dist/hooks/use-submit/use-submit.constants.d.ts +8 -0
  149. package/dist/hooks/use-submit/use-submit.constants.d.ts.map +1 -0
  150. package/dist/hooks/use-submit/use-submit.hooks.d.ts +10 -0
  151. package/dist/hooks/use-submit/use-submit.hooks.d.ts.map +1 -0
  152. package/dist/hooks/use-submit/use-submit.types.d.ts +115 -0
  153. package/dist/hooks/use-submit/use-submit.types.d.ts.map +1 -0
  154. package/dist/index.d.ts +12 -733
  155. package/dist/index.d.ts.map +1 -0
  156. package/dist/index.mjs +1935 -0
  157. package/dist/index.mjs.map +1 -0
  158. package/dist/provider/index.d.ts +3 -0
  159. package/dist/provider/index.d.ts.map +1 -0
  160. package/dist/provider/provider.d.ts +13 -0
  161. package/dist/provider/provider.d.ts.map +1 -0
  162. package/dist/provider/provider.types.d.ts +31 -0
  163. package/dist/provider/provider.types.d.ts.map +1 -0
  164. package/dist/utils/bounce.utils.d.ts +8 -0
  165. package/dist/utils/bounce.utils.d.ts.map +1 -0
  166. package/dist/utils/deep-equal.utils.d.ts +14 -0
  167. package/dist/utils/deep-equal.utils.d.ts.map +1 -0
  168. package/dist/utils/index.d.ts +4 -0
  169. package/dist/utils/index.d.ts.map +1 -0
  170. package/dist/utils/tracked-proxy.utils.d.ts +7 -0
  171. package/dist/utils/tracked-proxy.utils.d.ts.map +1 -0
  172. package/package.json +21 -13
  173. package/src/helpers/use-request-events/use-request-events.hooks.ts +60 -14
  174. package/src/helpers/use-request-events/use-request-events.types.ts +19 -12
  175. package/src/helpers/use-socket-state/use-socket-state.constants.ts +2 -2
  176. package/src/helpers/use-socket-state/use-socket-state.hooks.ts +47 -13
  177. package/src/helpers/use-socket-state/use-socket-state.types.ts +1 -1
  178. package/src/helpers/use-tracked-state/use-tracked-state.constants.ts +1 -1
  179. package/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +74 -22
  180. package/src/helpers/use-tracked-state/use-tracked-state.types.ts +7 -2
  181. package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +39 -4
  182. package/src/hooks/use-app-manager/use-app-manager.hooks.ts +2 -2
  183. package/src/hooks/use-cache/use-cache.hooks.ts +33 -41
  184. package/src/hooks/use-cache/use-cache.types.ts +3 -3
  185. package/src/hooks/use-emitter/use-emitter.hooks.ts +17 -16
  186. package/src/hooks/use-fetch/use-fetch.constants.ts +5 -2
  187. package/src/hooks/use-fetch/use-fetch.hooks.ts +109 -51
  188. package/src/hooks/use-fetch/use-fetch.types.ts +18 -3
  189. package/src/hooks/use-listener/use-listener.hooks.ts +19 -27
  190. package/src/hooks/use-queue/use-queue.constants.ts +2 -2
  191. package/src/hooks/use-queue/use-queue.hooks.ts +25 -6
  192. package/src/hooks/use-queue/use-queue.types.ts +8 -2
  193. package/src/hooks/use-stream/index.ts +2 -0
  194. package/src/hooks/use-stream/use-stream.hooks.ts +164 -0
  195. package/src/hooks/use-stream/use-stream.types.ts +53 -0
  196. package/src/hooks/use-submit/use-submit.constants.ts +2 -2
  197. package/src/hooks/use-submit/use-submit.hooks.ts +43 -48
  198. package/src/hooks/use-submit/use-submit.types.ts +9 -9
  199. package/src/index.ts +1 -0
  200. package/src/provider/provider.tsx +1 -1
  201. package/src/provider/provider.types.ts +8 -8
  202. package/src/utils/index.ts +1 -0
  203. package/src/utils/tracked-proxy.utils.ts +19 -0
  204. package/tsconfig.json +1 -1
  205. package/vite.config.ts +45 -0
  206. package/.eslintrc.json +0 -11
  207. package/__tests__/features/use-fetch/use-fetch.suspense.ts +0 -37
  208. package/__tests__/global.d.ts +0 -1
  209. package/__tests__/jest.setup.ts +0 -9
  210. package/dist/index.js +0 -1541
  211. package/dist/index.js.map +0 -7
  212. 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
- jest.resetModules();
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 = jest.fn();
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 = jest.fn();
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 = jest.fn();
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 = jest.fn();
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 = jest.fn();
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 = jest.fn();
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
- jest.resetModules();
28
- request = createRequest<{ queryParams?: string }>({ method: "POST" });
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 = jest.fn();
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 = jest.fn();
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 = jest.fn();
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).toHaveBeenCalledTimes(3);
69
+ expect(spy.mock.calls.length).toBeGreaterThanOrEqual(1);
72
70
  });
73
71
  it("should trigger onUploadProgress helper", async () => {
74
- const spy = jest.fn();
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).toHaveBeenCalledTimes(3);
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 = jest.fn();
88
- const spy2 = jest.fn();
89
- const spy3 = jest.fn();
90
- const spy4 = jest.fn();
91
- const spy5 = jest.fn();
92
- const spy6 = jest.fn();
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).toHaveBeenCalledTimes(9);
112
- expect(spy4).toHaveBeenCalledTimes(9);
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 = jest.fn();
120
- const unusedSpy = jest.fn();
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 = jest.fn();
136
- const unusedSpy = jest.fn();
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 = jest.fn();
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 = jest.fn();
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 = jest.fn();
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 = jest.fn();
196
- const spy2 = jest.fn();
197
- const spy3 = jest.fn();
198
- const spy4 = jest.fn();
199
- const spy5 = jest.fn();
200
- const spy6 = jest.fn();
201
- const spy7 = jest.fn();
202
- const spy8 = jest.fn();
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).toHaveBeenCalledTimes(6);
226
- expect(spy4).toHaveBeenCalledTimes(6);
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 = jest.fn();
234
- const spy2 = jest.fn();
235
- const spy3 = jest.fn();
236
- const spy4 = jest.fn();
237
- const spy5 = jest.fn();
238
- const spy6 = jest.fn();
239
- const spy7 = jest.fn();
240
- const spy8 = jest.fn();
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).toHaveBeenCalledTimes(6);
270
- expect(spy4).toHaveBeenCalledTimes(6);
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);