@fireproof/core 0.20.0-dev-preview-51 → 0.20.0-dev-preview-53

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.
@@ -1,22 +1,32 @@
1
1
  import { renderHook, waitFor } from "@testing-library/react";
2
2
  import { describe, expect, it } from "vitest";
3
+ import { fireproof, useFireproof } from "use-fireproof";
4
+ import type { Database, LiveQueryResult, UseDocumentResult } from "use-fireproof";
3
5
 
4
- import { Database, fireproof, useFireproof } from "use-fireproof";
5
- import { LiveQueryResult, UseDocumentResult } from "use-fireproof";
6
+ // Test timeout value for CI
7
+ const TEST_TIMEOUT = 45000;
6
8
 
7
9
  describe("HOOK: useFireproof", () => {
8
- it("should be defined", () => {
9
- expect(useFireproof).toBeDefined();
10
- });
11
-
12
- it("renders the hook correctly and checks types", () => {
13
- renderHook(() => {
14
- const { database, useLiveQuery, useDocument } = useFireproof("dbname");
15
- expect(typeof useLiveQuery).toBe("function");
16
- expect(typeof useDocument).toBe("function");
17
- expect(database?.constructor.name).toMatch(/^Database/);
18
- });
19
- });
10
+ it(
11
+ "should be defined",
12
+ () => {
13
+ expect(useFireproof).toBeDefined();
14
+ },
15
+ TEST_TIMEOUT,
16
+ );
17
+
18
+ it(
19
+ "renders the hook correctly and checks types",
20
+ () => {
21
+ renderHook(() => {
22
+ const { database, useLiveQuery, useDocument } = useFireproof("dbname");
23
+ expect(typeof useLiveQuery).toBe("function");
24
+ expect(typeof useDocument).toBe("function");
25
+ expect(database?.constructor.name).toMatch(/^Database/);
26
+ });
27
+ },
28
+ TEST_TIMEOUT,
29
+ );
20
30
  });
21
31
 
22
32
  describe("HOOK: useFireproof useLiveQuery has results", () => {
@@ -36,32 +46,32 @@ describe("HOOK: useFireproof useLiveQuery has results", () => {
36
46
  cnt++;
37
47
  });
38
48
 
39
- it("should have setup data", async () => {
40
- const allDocs = await db.allDocs<{ foo: string }>();
41
- expect(allDocs.rows.length).toBe(3);
42
- expect(allDocs.rows[0].value.foo).toBe("aha");
43
- expect(allDocs.rows[1].value.foo).toBe("bar");
44
- expect(allDocs.rows[2].value.foo).toBe("caz");
45
- });
46
-
47
- it("queries correctly", async () => {
48
- renderHook(() => {
49
- const result = useFireproof(dbName);
50
- database = result.database;
51
- useLiveQuery = result.useLiveQuery;
52
- query = useLiveQuery<{ foo: string }>("foo");
53
- });
54
-
55
- await waitFor(() => {
56
- // act(() => {
57
- // expect(query.rows).toBe([]);
58
- expect(query.rows.length).toBe(3);
59
- expect(query.rows[0].doc?.foo).toBe("aha");
60
- expect(query.rows[1].doc?.foo).toBe("bar");
61
- expect(query.rows[2].doc?.foo).toBe("caz");
62
- // });
63
- });
64
- });
49
+ it(
50
+ "should have setup data",
51
+ async () => {
52
+ const allDocs = await db.allDocs<{ foo: string }>();
53
+ const expectedValues = ["aha", "bar", "caz"];
54
+ expect(allDocs.rows.map((row) => row.value.foo)).toEqual(expectedValues);
55
+ },
56
+ TEST_TIMEOUT,
57
+ );
58
+
59
+ it(
60
+ "queries correctly",
61
+ async () => {
62
+ renderHook(() => {
63
+ const result = useFireproof(dbName);
64
+ database = result.database;
65
+ useLiveQuery = result.useLiveQuery;
66
+ query = useLiveQuery<{ foo: string }>("foo");
67
+ });
68
+
69
+ await waitFor(() => {
70
+ expect(query.rows.map((row) => row.doc?.foo)).toEqual(["aha", "bar", "caz"]);
71
+ });
72
+ },
73
+ TEST_TIMEOUT,
74
+ );
65
75
 
66
76
  afterEach(async () => {
67
77
  await db.close();
@@ -89,93 +99,111 @@ describe("HOOK: useFireproof useDocument has results", () => {
89
99
  });
90
100
  });
91
101
 
92
- it("should have empty setup data", async () => {
93
- const allDocs = await db.allDocs<{ input: string }>();
94
- expect(allDocs.rows.length).toBe(0);
95
- });
96
-
97
- it("queries correctly", async () => {
98
- await waitFor(() => {
99
- expect(docResult.doc.input).toBe("");
100
- expect(docResult.doc._id).toBeUndefined();
101
- });
102
- });
103
-
104
- it("handles mutations correctly", async () => {
105
- docResult.merge({ input: "new" });
106
- await waitFor(() => {
107
- expect(docResult.doc.input).toBe("new");
108
- expect(docResult.doc._id).toBeUndefined();
109
- });
110
- });
111
-
112
- it("handles save correctly", async () => {
113
- docResult.merge({ input: "first" });
114
- await waitFor(() => {
115
- expect(docResult.doc.input).toBe("first");
116
- expect(docResult.doc._id).toBeUndefined();
117
- });
118
-
119
- renderHook(() => {
120
- docResult.save();
121
- });
122
-
123
- await waitFor(() => {
124
- expect(docResult.doc._id).toBeDefined();
125
- });
126
- });
127
-
128
- it("handles reset after save", async () => {
129
- docResult.merge({ input: "new" });
130
- await waitFor(() => {
131
- expect(docResult.doc.input).toBe("new");
132
- expect(docResult.doc._id).toBeUndefined();
133
- });
134
-
135
- renderHook(() => {
136
- docResult.save();
137
- });
138
-
139
- await waitFor(() => {
140
- expect(docResult.doc._id).toBeDefined();
141
- });
142
-
143
- const doc1 = await db.get<{ input: string }>(docResult.doc._id);
144
- expect(doc1.input).toBe("new");
145
-
146
- renderHook(() => {
147
- docResult.reset();
148
- });
149
-
150
- await waitFor(() => {
151
- expect(docResult.doc.input).toBe("");
152
- expect(docResult.doc._id).toBeUndefined();
153
- });
154
-
155
- renderHook(() => {
156
- docResult.merge({ input: "fresh" });
157
- });
158
-
159
- renderHook(() => {
160
- docResult.save();
161
- });
162
-
163
- await waitFor(() => {
164
- expect(docResult.doc.input).toBe("fresh");
165
- expect(docResult.doc._id).toBeDefined();
166
- });
167
-
168
- const doc2 = await db.get<{ input: string }>(docResult.doc._id);
169
- expect(doc2.input).toBe("fresh");
170
- expect(doc2._id).toBe(docResult.doc._id);
171
- expect(doc1._id).not.toBe(doc2._id);
172
-
173
- const allDocs = await db.allDocs<{ input: string }>();
174
- expect(allDocs.rows.length).toBe(3);
175
- expect(allDocs.rows[0].value.input).toBe("first");
176
- expect(allDocs.rows[1].value.input).toBe("new");
177
- expect(allDocs.rows[2].value.input).toBe("fresh");
178
- });
102
+ it(
103
+ "should have empty setup data",
104
+ async () => {
105
+ const allDocs = await db.allDocs<{ input: string }>();
106
+ expect(allDocs.rows.length).toBe(0);
107
+ },
108
+ TEST_TIMEOUT,
109
+ );
110
+
111
+ it(
112
+ "queries correctly",
113
+ async () => {
114
+ await waitFor(() => {
115
+ expect(docResult.doc.input).toBe("");
116
+ expect(docResult.doc._id).toBeUndefined();
117
+ });
118
+ },
119
+ TEST_TIMEOUT,
120
+ );
121
+
122
+ it(
123
+ "handles mutations correctly",
124
+ async () => {
125
+ docResult.merge({ input: "new" });
126
+ await waitFor(() => {
127
+ expect(docResult.doc.input).toBe("new");
128
+ expect(docResult.doc._id).toBeUndefined();
129
+ });
130
+ },
131
+ TEST_TIMEOUT,
132
+ );
133
+
134
+ it(
135
+ "handles save correctly",
136
+ async () => {
137
+ docResult.merge({ input: "first" });
138
+ await waitFor(() => {
139
+ expect(docResult.doc.input).toBe("first");
140
+ expect(docResult.doc._id).toBeUndefined();
141
+ });
142
+
143
+ renderHook(() => {
144
+ docResult.save();
145
+ });
146
+
147
+ await waitFor(() => {
148
+ expect(docResult.doc._id).toBeDefined();
149
+ });
150
+ },
151
+ TEST_TIMEOUT,
152
+ );
153
+
154
+ it(
155
+ "handles reset after save",
156
+ async () => {
157
+ docResult.merge({ input: "new" });
158
+ await waitFor(() => {
159
+ expect(docResult.doc.input).toBe("new");
160
+ expect(docResult.doc._id).toBeUndefined();
161
+ });
162
+
163
+ renderHook(() => {
164
+ docResult.save();
165
+ });
166
+
167
+ await waitFor(() => {
168
+ expect(docResult.doc._id).toBeDefined();
169
+ });
170
+
171
+ const doc1 = await db.get<{ input: string }>(docResult.doc._id);
172
+ expect(doc1.input).toBe("new");
173
+
174
+ renderHook(() => {
175
+ docResult.reset();
176
+ });
177
+
178
+ await waitFor(() => {
179
+ expect(docResult.doc.input).toBe("");
180
+ expect(docResult.doc._id).toBeUndefined();
181
+ });
182
+
183
+ renderHook(() => {
184
+ docResult.merge({ input: "fresh" });
185
+ });
186
+
187
+ renderHook(() => {
188
+ docResult.save();
189
+ });
190
+
191
+ await waitFor(() => {
192
+ expect(docResult.doc.input).toBe("fresh");
193
+ expect(docResult.doc._id).toBeDefined();
194
+ });
195
+
196
+ const doc2 = await db.get<{ input: string }>(docResult.doc._id);
197
+ expect(doc2.input).toBe("fresh");
198
+ expect(doc2._id).toBe(docResult.doc._id);
199
+ expect(doc1._id).not.toBe(doc2._id);
200
+
201
+ const allDocs = await db.allDocs<{ input: string }>();
202
+ const inputs = allDocs.rows.map((r) => r.value.input);
203
+ expect(inputs).toEqual(expect.arrayContaining(["first", "new", "fresh"]));
204
+ },
205
+ TEST_TIMEOUT,
206
+ );
179
207
 
180
208
  afterEach(async () => {
181
209
  await db.close();
@@ -203,81 +231,101 @@ describe("HOOK: useFireproof useDocument has results reset sync", () => {
203
231
  });
204
232
  });
205
233
 
206
- it("should have empty setup data", async () => {
207
- const allDocs = await db.allDocs<{ input: string }>();
208
- expect(allDocs.rows.length).toBe(0);
209
- });
210
-
211
- it("queries correctly", async () => {
212
- await waitFor(() => {
213
- expect(docResult.doc.input).toBe("");
214
- expect(docResult.doc._id).toBeUndefined();
215
- });
216
- });
217
-
218
- it("handles mutations correctly", async () => {
219
- docResult.merge({ input: "new" });
220
- await waitFor(() => {
221
- expect(docResult.doc.input).toBe("new");
222
- expect(docResult.doc._id).toBeUndefined();
223
- });
224
- });
225
-
226
- it("handles save correctly", async () => {
227
- docResult.merge({ input: "first" });
228
- await waitFor(() => {
229
- expect(docResult.doc.input).toBe("first");
230
- expect(docResult.doc._id).toBeUndefined();
231
- });
232
-
233
- renderHook(() => {
234
- docResult.save();
235
- });
236
-
237
- await waitFor(() => {
238
- expect(docResult.doc._id).toBeDefined();
239
- });
240
- });
241
-
242
- it("handles reset after save", async () => {
243
- docResult.merge({ input: "new" });
244
- await waitFor(() => {
245
- expect(docResult.doc.input).toBe("new");
246
- expect(docResult.doc._id).toBeUndefined();
247
- });
248
-
249
- renderHook(() => {
250
- docResult.save();
251
- docResult.reset();
252
- });
253
-
254
- await waitFor(() => {
255
- expect(docResult.doc.input).toBe("");
256
- expect(docResult.doc._id).toBeUndefined();
257
- });
258
-
259
- renderHook(() => {
260
- docResult.merge({ input: "fresh" });
261
- });
262
-
263
- renderHook(() => {
264
- docResult.save();
265
- });
266
-
267
- await waitFor(() => {
268
- expect(docResult.doc.input).toBe("fresh");
269
- expect(docResult.doc._id).toBeDefined();
270
- });
271
-
272
- const doc2 = await db.get<{ input: string }>(docResult.doc._id);
273
- expect(doc2.input).toBe("fresh");
274
- expect(doc2._id).toBe(docResult.doc._id);
275
-
276
- const allDocs = await db.allDocs<{ input: string }>();
277
- expect(allDocs.rows.length).toBe(3);
278
- const inputs = allDocs.rows.map((r) => r.value.input);
279
- expect(inputs).toEqual(expect.arrayContaining(["first", "new", "fresh"]));
280
- });
234
+ it(
235
+ "should have empty setup data",
236
+ async () => {
237
+ const allDocs = await db.allDocs<{ input: string }>();
238
+ expect(allDocs.rows.length).toBe(0);
239
+ },
240
+ TEST_TIMEOUT,
241
+ );
242
+
243
+ it(
244
+ "queries correctly",
245
+ async () => {
246
+ await waitFor(() => {
247
+ expect(docResult.doc.input).toBe("");
248
+ expect(docResult.doc._id).toBeUndefined();
249
+ });
250
+ },
251
+ TEST_TIMEOUT,
252
+ );
253
+
254
+ it(
255
+ "handles mutations correctly",
256
+ async () => {
257
+ docResult.merge({ input: "new" });
258
+ await waitFor(() => {
259
+ expect(docResult.doc.input).toBe("new");
260
+ expect(docResult.doc._id).toBeUndefined();
261
+ });
262
+ },
263
+ TEST_TIMEOUT,
264
+ );
265
+
266
+ it(
267
+ "handles save correctly",
268
+ async () => {
269
+ docResult.merge({ input: "first" });
270
+ await waitFor(() => {
271
+ expect(docResult.doc.input).toBe("first");
272
+ expect(docResult.doc._id).toBeUndefined();
273
+ });
274
+
275
+ renderHook(() => {
276
+ docResult.save();
277
+ });
278
+
279
+ await waitFor(() => {
280
+ expect(docResult.doc._id).toBeDefined();
281
+ });
282
+ },
283
+ TEST_TIMEOUT,
284
+ );
285
+
286
+ it(
287
+ "handles reset after save",
288
+ async () => {
289
+ docResult.merge({ input: "new" });
290
+ await waitFor(() => {
291
+ expect(docResult.doc.input).toBe("new");
292
+ expect(docResult.doc._id).toBeUndefined();
293
+ });
294
+
295
+ renderHook(() => {
296
+ docResult.save();
297
+ docResult.reset();
298
+ });
299
+
300
+ await waitFor(() => {
301
+ expect(docResult.doc.input).toBe("");
302
+ expect(docResult.doc._id).toBeUndefined();
303
+ });
304
+
305
+ renderHook(() => {
306
+ docResult.merge({ input: "fresh" });
307
+ });
308
+
309
+ renderHook(() => {
310
+ docResult.save();
311
+ });
312
+
313
+ await waitFor(() => {
314
+ expect(docResult.doc.input).toBe("fresh");
315
+ expect(docResult.doc._id).toBeDefined();
316
+ });
317
+
318
+ const doc2 = await db.get<{ input: string }>(docResult.doc._id);
319
+ expect(doc2.input).toBe("fresh");
320
+ expect(doc2._id).toBe(docResult.doc._id);
321
+
322
+ const allDocs = await db.allDocs<{ input: string }>();
323
+ expect(allDocs.rows.length).toBe(3);
324
+ const inputs = allDocs.rows.map((r) => r.value.input);
325
+ expect(inputs).toEqual(expect.arrayContaining(["first", "new", "fresh"]));
326
+ },
327
+ TEST_TIMEOUT,
328
+ );
281
329
 
282
330
  afterEach(async () => {
283
331
  await db.close();
@@ -308,38 +356,50 @@ describe("HOOK: useFireproof useDocument with existing document has results", ()
308
356
  });
309
357
  });
310
358
 
311
- it("should have setup data", async () => {
312
- const allDocs = await db.allDocs<{ input: string }>();
313
- expect(allDocs.rows.length).toBe(1);
314
- expect(allDocs.rows[0].value.input).toBe("initial");
315
- expect(allDocs.rows[0].key).toBe(id);
316
- });
317
-
318
- it("queries correctly", async () => {
319
- await waitFor(() => {
320
- expect(docResult.doc.input).toBe("initial");
321
- expect(docResult.doc._id).toBe(id);
322
- });
323
- });
324
-
325
- it("handles mutations correctly", async () => {
326
- // First verify initial state
327
- await waitFor(() => {
328
- expect(docResult.doc.input).toBe("initial");
329
- expect(docResult.doc._id).toBe(id);
330
- });
331
-
332
- // Run merge in hook context
333
- renderHook(() => {
334
- docResult.merge({ input: "new" });
335
- });
336
-
337
- // Then verify the mutation took effect
338
- await waitFor(() => {
339
- expect(docResult.doc.input).toBe("new");
340
- expect(docResult.doc._id).toBe(id);
341
- });
342
- });
359
+ it(
360
+ "should have setup data",
361
+ async () => {
362
+ const allDocs = await db.allDocs<{ input: string }>();
363
+ expect(allDocs.rows.length).toBe(1);
364
+ expect(allDocs.rows[0].value.input).toBe("initial");
365
+ expect(allDocs.rows[0].key).toBe(id);
366
+ },
367
+ TEST_TIMEOUT,
368
+ );
369
+
370
+ it(
371
+ "queries correctly",
372
+ async () => {
373
+ await waitFor(() => {
374
+ expect(docResult.doc.input).toBe("initial");
375
+ expect(docResult.doc._id).toBe(id);
376
+ });
377
+ },
378
+ TEST_TIMEOUT,
379
+ );
380
+
381
+ it(
382
+ "handles mutations correctly",
383
+ async () => {
384
+ // First verify initial state
385
+ await waitFor(() => {
386
+ expect(docResult.doc.input).toBe("initial");
387
+ expect(docResult.doc._id).toBe(id);
388
+ });
389
+
390
+ // Run merge in hook context
391
+ renderHook(() => {
392
+ docResult.merge({ input: "new" });
393
+ });
394
+
395
+ // Then verify the mutation took effect
396
+ await waitFor(() => {
397
+ expect(docResult.doc.input).toBe("new");
398
+ expect(docResult.doc._id).toBe(id);
399
+ });
400
+ },
401
+ TEST_TIMEOUT,
402
+ );
343
403
 
344
404
  afterEach(async () => {
345
405
  await db.close();
@@ -370,39 +430,51 @@ describe("HOOK: useFireproof useDocument with existing document handles external
370
430
  });
371
431
  });
372
432
 
373
- it("should have setup data", async () => {
374
- const allDocs = await db.allDocs<{ input: string }>();
375
- expect(allDocs.rows.length).toBe(1);
376
- expect(allDocs.rows[0].value.input).toBe("initial");
377
- expect(allDocs.rows[0].key).toBe(id);
378
- });
379
-
380
- it("queries correctly", async () => {
381
- await waitFor(() => {
382
- expect(docResult.doc.input).toBe("initial");
383
- expect(docResult.doc._id).toBe(id);
384
- });
385
- });
386
-
387
- it("handles mutations correctly", async () => {
388
- // First verify initial state
389
- await waitFor(() => {
390
- expect(docResult.doc.input).toBe("initial");
391
- expect(docResult.doc._id).toBe(id);
392
- });
393
-
394
- // Run merge in hook context
395
- renderHook(() => {
396
- // docResult.merge({ input: "new" });
397
- db.put({ _id: id, input: "external" });
398
- });
399
-
400
- // Then verify the mutation took effect
401
- await waitFor(() => {
402
- expect(docResult.doc.input).toBe("external");
403
- expect(docResult.doc._id).toBe(id);
404
- });
405
- });
433
+ it(
434
+ "should have setup data",
435
+ async () => {
436
+ const allDocs = await db.allDocs<{ input: string }>();
437
+ expect(allDocs.rows.length).toBe(1);
438
+ expect(allDocs.rows[0].value.input).toBe("initial");
439
+ expect(allDocs.rows[0].key).toBe(id);
440
+ },
441
+ TEST_TIMEOUT,
442
+ );
443
+
444
+ it(
445
+ "queries correctly",
446
+ async () => {
447
+ await waitFor(() => {
448
+ expect(docResult.doc.input).toBe("initial");
449
+ expect(docResult.doc._id).toBe(id);
450
+ });
451
+ },
452
+ TEST_TIMEOUT,
453
+ );
454
+
455
+ it(
456
+ "handles mutations correctly",
457
+ async () => {
458
+ // First verify initial state
459
+ await waitFor(() => {
460
+ expect(docResult.doc.input).toBe("initial");
461
+ expect(docResult.doc._id).toBe(id);
462
+ });
463
+
464
+ // Run merge in hook context
465
+ renderHook(() => {
466
+ // docResult.merge({ input: "new" });
467
+ db.put({ _id: id, input: "external" });
468
+ });
469
+
470
+ // Then verify the mutation took effect
471
+ await waitFor(() => {
472
+ expect(docResult.doc.input).toBe("external");
473
+ expect(docResult.doc._id).toBe(id);
474
+ });
475
+ },
476
+ TEST_TIMEOUT,
477
+ );
406
478
 
407
479
  afterEach(async () => {
408
480
  await db.close();
@@ -430,45 +502,49 @@ describe("HOOK: useFireproof bug fix: once the ID is set, it can reset", () => {
430
502
  });
431
503
  });
432
504
 
433
- it("ensures save() then reset() yields an ephemeral doc (blank _id)", async () => {
434
- // Merge some changes
435
- docResult.merge({ input: "temp data" });
436
- await waitFor(() => {
437
- expect(docResult.doc.input).toBe("temp data");
438
- expect(docResult.doc._id).toBeUndefined();
439
- });
440
-
441
- // Save
442
- renderHook(() => {
443
- docResult.save();
444
- docResult.reset();
445
- });
446
-
447
- await waitFor(() => {
448
- expect(docResult.doc._id).toBeUndefined();
449
- expect(docResult.doc.input).toBe("");
450
- });
451
-
452
- renderHook(() => {
453
- docResult.merge({ input: "new temp data" });
454
- });
455
-
456
- renderHook(() => {
457
- docResult.save();
458
- });
459
-
460
- await waitFor(() => {
461
- expect(docResult.doc._id).toBeDefined();
462
- expect(docResult.doc.input).toBe("new temp data");
463
- });
464
-
465
- // Confirm it's actually in the DB
466
- const allDocs = await db.allDocs<{ input: string }>();
467
- expect(allDocs.rows.length).toBe(2);
468
- const docInputs = allDocs.rows.map((row) => row.value.input);
469
- expect(docInputs).toContain("temp data");
470
- expect(docInputs).toContain("new temp data");
471
- });
505
+ it(
506
+ "ensures save() then reset() yields an ephemeral doc (blank _id)",
507
+ async () => {
508
+ // Merge some changes
509
+ docResult.merge({ input: "temp data" });
510
+ await waitFor(() => {
511
+ expect(docResult.doc.input).toBe("temp data");
512
+ expect(docResult.doc._id).toBeUndefined();
513
+ });
514
+
515
+ // Save
516
+ renderHook(() => {
517
+ docResult.save();
518
+ docResult.reset();
519
+ });
520
+
521
+ await waitFor(() => {
522
+ expect(docResult.doc._id).toBeUndefined();
523
+ expect(docResult.doc.input).toBe("");
524
+ });
525
+
526
+ renderHook(() => {
527
+ docResult.merge({ input: "new temp data" });
528
+ });
529
+
530
+ renderHook(() => {
531
+ docResult.save();
532
+ });
533
+
534
+ await waitFor(() => {
535
+ expect(docResult.doc._id).toBeDefined();
536
+ expect(docResult.doc.input).toBe("new temp data");
537
+ });
538
+
539
+ // Confirm it's actually in the DB
540
+ const allDocs = await db.allDocs<{ input: string }>();
541
+ expect(allDocs.rows.length).toBe(2);
542
+ const docInputs = allDocs.rows.map((row) => row.value.input);
543
+ expect(docInputs).toContain("temp data");
544
+ expect(docInputs).toContain("new temp data");
545
+ },
546
+ TEST_TIMEOUT,
547
+ );
472
548
 
473
549
  afterEach(async () => {
474
550
  await db.close();
@@ -492,24 +568,28 @@ describe("HOOK: useFireproof race condition: calling save() without await overwr
492
568
  });
493
569
  });
494
570
 
495
- it("demonstrates that calling docResult.save() and docResult.reset() in the same tick can overwrite reset", async () => {
496
- // Merge some changes into doc
497
- docResult.merge({ input: "some data" });
571
+ it(
572
+ "demonstrates that calling docResult.save() and docResult.reset() in the same tick can overwrite reset",
573
+ async () => {
574
+ // Merge some changes into doc
575
+ docResult.merge({ input: "some data" });
498
576
 
499
- // Call save() but DO NOT await it, then immediately reset().
500
- docResult.save();
501
- docResult.reset();
577
+ // Call save() but DO NOT await it, then immediately reset().
578
+ docResult.save();
579
+ docResult.reset();
502
580
 
503
- // Let the async subscription produce a new doc in case the doc is reloaded with an _id
504
- await new Promise((resolve) => setTimeout(resolve, 500));
581
+ // Let the async subscription produce a new doc in case the doc is reloaded with an _id
582
+ await new Promise((resolve) => setTimeout(resolve, 500));
505
583
 
506
- // If the reset worked, doc._id should STILL be undefined.
507
- // If the subscription wins, doc._id will be defined => test fails.
508
- await waitFor(() => {
509
- expect(docResult.doc._id).toBeUndefined();
510
- expect(docResult.doc.input).toBe("");
511
- });
512
- });
584
+ // If the reset worked, doc._id should STILL be undefined.
585
+ // If the subscription wins, doc._id will be defined => test fails.
586
+ await waitFor(() => {
587
+ expect(docResult.doc._id).toBeUndefined();
588
+ expect(docResult.doc.input).toBe("");
589
+ });
590
+ },
591
+ TEST_TIMEOUT,
592
+ );
513
593
 
514
594
  afterEach(async () => {
515
595
  await db.close();
@@ -531,22 +611,26 @@ describe("useFireproo calling submit()", () => {
531
611
  });
532
612
  });
533
613
 
534
- it("demonstrates that calling docResult.save() and docResult.reset() in the same tick can overwrite reset", async () => {
535
- // Merge some changes into doc
536
- docResult.merge({ input: "some data" });
614
+ it(
615
+ "demonstrates that calling docResult.save() and docResult.reset() in the same tick can overwrite reset",
616
+ async () => {
617
+ // Merge some changes into doc
618
+ docResult.merge({ input: "some data" });
537
619
 
538
- docResult.submit();
620
+ docResult.submit();
539
621
 
540
- // Let the async subscription produce a new doc in case the doc is reloaded with an _id
541
- await new Promise((resolve) => setTimeout(resolve, 500));
622
+ // Let the async subscription produce a new doc in case the doc is reloaded with an _id
623
+ await new Promise((resolve) => setTimeout(resolve, 500));
542
624
 
543
- // If the reset worked, doc._id should STILL be undefined.
544
- // If the subscription wins, doc._id will be defined => test fails.
545
- await waitFor(() => {
546
- expect(docResult.doc._id).toBeUndefined();
547
- expect(docResult.doc.input).toBe("");
548
- });
549
- });
625
+ // If the reset worked, doc._id should STILL be undefined.
626
+ // If the subscription wins, doc._id will be defined => test fails.
627
+ await waitFor(() => {
628
+ expect(docResult.doc._id).toBeUndefined();
629
+ expect(docResult.doc.input).toBe("");
630
+ });
631
+ },
632
+ TEST_TIMEOUT,
633
+ );
550
634
 
551
635
  afterEach(async () => {
552
636
  await db.close();