@react-magma/dropzone 13.0.1-rc.0 → 14.0.0-next.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.
@@ -1,6 +1,12 @@
1
1
  import React from 'react';
2
2
 
3
- import { cleanup, render, fireEvent, waitFor } from '@testing-library/react';
3
+ import {
4
+ cleanup,
5
+ render,
6
+ act,
7
+ fireEvent,
8
+ waitFor,
9
+ } from '@testing-library/react';
4
10
  import userEvent from '@testing-library/user-event';
5
11
  import { I18nContext, defaultI18n, magma } from 'react-magma-dom';
6
12
 
@@ -15,6 +21,7 @@ describe('File Uploader', () => {
15
21
  window.URL.revokeObjectURL = jest.fn();
16
22
 
17
23
  beforeEach(() => {
24
+ jest.useFakeTimers();
18
25
  files = [createFile('file1.pdf', 1111, 'application/pdf')];
19
26
  images = [
20
27
  createFile('cats.png', 1234, 'image/png'),
@@ -23,6 +30,7 @@ describe('File Uploader', () => {
23
30
  });
24
31
 
25
32
  afterEach(() => {
33
+ jest.useRealTimers();
26
34
  window.URL.createObjectURL.mockReset();
27
35
  cleanup();
28
36
  });
@@ -48,7 +56,6 @@ describe('File Uploader', () => {
48
56
 
49
57
  it('should find element by testId', () => {
50
58
  const testId = 'test-id';
51
-
52
59
  const { getByTestId } = render(<Dropzone testId={testId} />);
53
60
 
54
61
  expect(getByTestId(testId)).toBeInTheDocument();
@@ -58,16 +65,21 @@ describe('File Uploader', () => {
58
65
  const { getByRole, getByTestId } = render(<Dropzone testId="testId" />);
59
66
 
60
67
  const fileInputClickFn = jest.fn();
68
+
61
69
  const fileInput = getByTestId('file-input');
62
70
 
63
71
  fileInput.click = fileInputClickFn;
64
72
 
65
- await userEvent.click(getByRole('button'));
73
+ userEvent.click(getByRole('button'));
66
74
 
67
- expect(fileInputClickFn).toHaveBeenCalled();
75
+ await waitFor(() => {
76
+ expect(fileInputClickFn).toHaveBeenCalled();
77
+ });
68
78
  });
69
79
 
70
80
  it('Does not violate accessibility standards', () => {
81
+ jest.useRealTimers();
82
+
71
83
  const { container } = render(<Dropzone />);
72
84
 
73
85
  return axe(container.innerHTML).then(result => {
@@ -77,7 +89,6 @@ describe('File Uploader', () => {
77
89
 
78
90
  it('Supports i18n', () => {
79
91
  const browseFiles = 'find those files';
80
-
81
92
  const { getByText } = render(
82
93
  <I18nContext.Provider
83
94
  value={{
@@ -97,11 +108,9 @@ describe('File Uploader', () => {
97
108
 
98
109
  it('sets {accept} prop on the <input>', () => {
99
110
  const accept = 'image/jpeg';
100
-
101
111
  const { container } = render(<Dropzone accept={accept} />);
102
112
 
103
113
  const input = container.querySelector('input');
104
-
105
114
  expect(input).toHaveAttribute('accept', accept);
106
115
  });
107
116
 
@@ -109,7 +118,6 @@ describe('File Uploader', () => {
109
118
  const { container } = render(<Dropzone multiple />);
110
119
 
111
120
  const input = container.querySelector('input');
112
-
113
121
  expect(input).toHaveAttribute('multiple');
114
122
  });
115
123
 
@@ -117,45 +125,35 @@ describe('File Uploader', () => {
117
125
  const { container } = render(<Dropzone />);
118
126
 
119
127
  const dropzone = container.querySelector('div');
128
+
120
129
  const dropEvt = new Event('drop', { bubbles: true });
121
130
  const dropEvtPreventDefaultSpy = jest.spyOn(dropEvt, 'preventDefault');
122
131
 
123
132
  fireEvent(dropzone, dropEvt);
124
-
125
133
  expect(dropEvtPreventDefaultSpy).toHaveBeenCalled();
126
134
  });
127
135
 
128
136
  it('border color changes for success', async () => {
129
137
  const data = createDtWithFiles(files);
130
138
  const testId = 'testId';
131
-
132
139
  const ui = <Dropzone testId={testId} />;
133
-
134
140
  const { getByTestId, rerender } = render(ui);
135
141
 
136
142
  const dropzone = getByTestId(testId);
137
-
138
143
  expect(dropzone).toHaveStyle(
139
144
  `border: 1px dashed ${magma.colors.neutral400}`
140
145
  );
141
146
 
142
147
  fireDragEnter(dropzone, data);
148
+ await flushPromises(rerender, ui);
143
149
 
144
- rerender(ui);
145
-
146
- await waitFor(() => {
147
- expect(dropzone).toHaveStyle(
148
- `border: 1px dashed ${magma.colors.success}`
149
- );
150
- });
150
+ expect(dropzone).toHaveStyle(`border: 1px dashed ${magma.colors.success}`);
151
151
  });
152
152
 
153
153
  it('border color changes for rejection', async () => {
154
154
  const data = createDtWithFiles(files);
155
155
  const testId = 'testId';
156
-
157
156
  const ui = <Dropzone accept="image/*" testId={testId} />;
158
-
159
157
  const { getByTestId, rerender } = render(ui);
160
158
 
161
159
  const dropzone = getByTestId(testId);
@@ -164,17 +162,13 @@ describe('File Uploader', () => {
164
162
  );
165
163
 
166
164
  fireDragEnter(dropzone, data);
165
+ await flushPromises(rerender, ui);
167
166
 
168
- rerender(ui);
169
-
170
- await waitFor(() => {
171
- expect(dropzone).toHaveStyle(`border: 1px dashed ${magma.colors.danger}`);
172
- });
167
+ expect(dropzone).toHaveStyle(`border: 1px dashed ${magma.colors.danger}`);
173
168
  });
174
169
 
175
170
  it('calls onSendFiles for a single file added via the input', async () => {
176
171
  const onSendFileSpy = jest.fn();
177
-
178
172
  const ui = <Dropzone sendFiles onSendFile={onSendFileSpy} />;
179
173
 
180
174
  const { container, rerender } = render(ui);
@@ -183,19 +177,15 @@ describe('File Uploader', () => {
183
177
  Object.defineProperty(input, 'files', { value: files });
184
178
 
185
179
  dispatchEvt(input, 'change');
180
+ await flushPromises(rerender, ui);
186
181
 
187
- rerender(ui);
188
-
189
- await waitFor(() => {
190
- expect(onSendFileSpy).toHaveBeenCalledWith(
191
- expect.objectContaining({ file: files[0] })
192
- );
193
- });
182
+ expect(onSendFileSpy).toHaveBeenCalledWith(
183
+ expect.objectContaining({ file: files[0] })
184
+ );
194
185
  });
195
186
 
196
187
  it('calls onSendFiles for multiple files added via the input', async () => {
197
188
  const onSendFileSpy = jest.fn();
198
-
199
189
  const ui = <Dropzone sendFiles onSendFile={onSendFileSpy} />;
200
190
 
201
191
  const { container, rerender } = render(ui);
@@ -204,17 +194,14 @@ describe('File Uploader', () => {
204
194
  Object.defineProperty(input, 'files', { value: images });
205
195
 
206
196
  dispatchEvt(input, 'change');
197
+ await flushPromises(rerender, ui);
207
198
 
208
- rerender(ui);
209
-
210
- await waitFor(() => {
211
- expect(onSendFileSpy).toHaveBeenCalledWith(
212
- expect.objectContaining({ file: images[0] })
213
- );
214
- expect(onSendFileSpy).toHaveBeenCalledWith(
215
- expect.objectContaining({ file: images[1] })
216
- );
217
- });
199
+ expect(onSendFileSpy).toHaveBeenCalledWith(
200
+ expect.objectContaining({ file: images[0] })
201
+ );
202
+ expect(onSendFileSpy).toHaveBeenCalledWith(
203
+ expect.objectContaining({ file: images[1] })
204
+ );
218
205
  });
219
206
 
220
207
  it('calls onSendFiles for a single file added via drop', async () => {
@@ -225,20 +212,16 @@ describe('File Uploader', () => {
225
212
  const ui = (
226
213
  <Dropzone sendFiles onSendFile={onSendFileSpy} testId={testId} />
227
214
  );
228
-
229
215
  const { getByTestId, rerender } = render(ui);
230
216
 
231
217
  const dropzone = getByTestId(testId);
232
-
233
218
  fireDrop(dropzone, data);
234
219
 
235
- rerender(ui);
220
+ await flushPromises(rerender, ui);
236
221
 
237
- await waitFor(() => {
238
- expect(onSendFileSpy).toHaveBeenCalledWith(
239
- expect.objectContaining({ file: files[0] })
240
- );
241
- });
222
+ expect(onSendFileSpy).toHaveBeenCalledWith(
223
+ expect.objectContaining({ file: files[0] })
224
+ );
242
225
  });
243
226
 
244
227
  it('calls onSendFiles for a multiple files added via drop', async () => {
@@ -249,23 +232,19 @@ describe('File Uploader', () => {
249
232
  const ui = (
250
233
  <Dropzone sendFiles onSendFile={onSendFileSpy} testId={testId} />
251
234
  );
252
-
253
235
  const { getByTestId, rerender } = render(ui);
254
236
 
255
237
  const dropzone = getByTestId(testId);
256
-
257
238
  fireDrop(dropzone, data);
258
239
 
259
- rerender(ui);
240
+ await flushPromises(rerender, ui);
260
241
 
261
- await waitFor(() => {
262
- expect(onSendFileSpy).toHaveBeenCalledWith(
263
- expect.objectContaining({ file: images[0] })
264
- );
265
- expect(onSendFileSpy).toHaveBeenCalledWith(
266
- expect.objectContaining({ file: images[1] })
267
- );
268
- });
242
+ expect(onSendFileSpy).toHaveBeenCalledWith(
243
+ expect.objectContaining({ file: images[0] })
244
+ );
245
+ expect(onSendFileSpy).toHaveBeenCalledWith(
246
+ expect.objectContaining({ file: images[1] })
247
+ );
269
248
  });
270
249
 
271
250
  it('delays calling onSendFiles until sendFiles is true', async () => {
@@ -280,26 +259,20 @@ describe('File Uploader', () => {
280
259
  testId={testId}
281
260
  />
282
261
  );
283
-
284
262
  const { getByTestId, rerender } = render(ui(false));
285
263
 
286
264
  const dropzone = getByTestId(testId);
287
-
288
265
  fireDrop(dropzone, data);
289
266
 
290
- rerender(ui(false));
267
+ await flushPromises(rerender, ui(false));
291
268
 
292
- await waitFor(() => {
293
- expect(onSendFileSpy).not.toHaveBeenCalled();
294
- });
269
+ expect(onSendFileSpy).not.toHaveBeenCalled();
295
270
 
296
- rerender(ui(true));
271
+ await flushPromises(rerender, ui(true));
297
272
 
298
- await waitFor(() => {
299
- expect(onSendFileSpy).toHaveBeenCalledWith(
300
- expect.objectContaining({ file: files[0] })
301
- );
302
- });
273
+ expect(onSendFileSpy).toHaveBeenCalledWith(
274
+ expect.objectContaining({ file: files[0] })
275
+ );
303
276
  });
304
277
 
305
278
  it('adds files to the file list', async () => {
@@ -311,14 +284,11 @@ describe('File Uploader', () => {
311
284
  const { getByTestId, getByText, rerender } = render(ui);
312
285
 
313
286
  const dropzone = getByTestId(testId);
314
-
315
287
  fireDrop(dropzone, data);
316
288
 
317
- rerender(ui);
289
+ await flushPromises(rerender, ui);
318
290
 
319
- await waitFor(() => {
320
- expect(getByText(files[0].name)).toBeInTheDocument();
321
- });
291
+ expect(getByText(files[0].name)).toBeInTheDocument();
322
292
  });
323
293
 
324
294
  it('preview for image files in the file list by default', async () => {
@@ -331,14 +301,11 @@ describe('File Uploader', () => {
331
301
  const { getByTestId, getByRole, rerender } = render(ui);
332
302
 
333
303
  const dropzone = getByTestId(testId);
334
-
335
304
  fireDrop(dropzone, data);
336
305
 
337
- rerender(ui);
306
+ await flushPromises(rerender, ui);
338
307
 
339
- await waitFor(() => {
340
- expect(getByRole('img')).toBeInTheDocument();
341
- });
308
+ expect(getByRole('img')).toBeInTheDocument();
342
309
  });
343
310
 
344
311
  it('previews for image files can be disabled', async () => {
@@ -353,14 +320,11 @@ describe('File Uploader', () => {
353
320
  const { getByTestId, queryByRole, rerender } = render(ui);
354
321
 
355
322
  const dropzone = getByTestId(testId);
356
-
357
323
  fireDrop(dropzone, data);
358
324
 
359
- rerender(ui);
325
+ await flushPromises(rerender, ui);
360
326
 
361
- await waitFor(() => {
362
- expect(queryByRole('img')).not.toBeInTheDocument();
363
- });
327
+ expect(queryByRole('img')).not.toBeInTheDocument();
364
328
  });
365
329
 
366
330
  it('shows errors on invalid file types in the file list', async () => {
@@ -372,14 +336,11 @@ describe('File Uploader', () => {
372
336
  const { getByTestId, getByText, rerender } = render(ui);
373
337
 
374
338
  const dropzone = getByTestId(testId);
375
-
376
339
  fireDrop(dropzone, data);
377
340
 
378
- rerender(ui);
341
+ await flushPromises(rerender, ui);
379
342
 
380
- await waitFor(() => {
381
- expect(getByText('Invalid File Type')).toBeInTheDocument();
382
- });
343
+ expect(getByText('Invalid File Type')).toBeInTheDocument();
383
344
  });
384
345
 
385
346
  it('shows errors on too many files in the file list', async () => {
@@ -391,16 +352,13 @@ describe('File Uploader', () => {
391
352
  const { getByTestId, getByText, rerender } = render(ui);
392
353
 
393
354
  const dropzone = getByTestId(testId);
394
-
395
355
  fireDrop(dropzone, data);
396
356
 
397
- rerender(ui);
357
+ await flushPromises(rerender, ui);
398
358
 
399
- await waitFor(() => {
400
- expect(
401
- getByText('You must upload a maximum of 1 files.')
402
- ).toBeInTheDocument();
403
- });
359
+ expect(
360
+ getByText('You must upload a maximum of 1 files.')
361
+ ).toBeInTheDocument();
404
362
  });
405
363
 
406
364
  it('shows errors on too few files in the file list', async () => {
@@ -414,13 +372,11 @@ describe('File Uploader', () => {
414
372
  const dropzone = getByTestId(testId);
415
373
  fireDrop(dropzone, data);
416
374
 
417
- rerender(ui);
375
+ await flushPromises(rerender, ui);
418
376
 
419
- await waitFor(() => {
420
- expect(
421
- getByText('You must upload a minimum of 6 files.')
422
- ).toBeInTheDocument();
423
- });
377
+ expect(
378
+ getByText('You must upload a minimum of 6 files.')
379
+ ).toBeInTheDocument();
424
380
  });
425
381
 
426
382
  it('shows errors on too large of a file in the file list', async () => {
@@ -432,16 +388,13 @@ describe('File Uploader', () => {
432
388
  const { getByTestId, getByText, rerender } = render(ui);
433
389
 
434
390
  const dropzone = getByTestId(testId);
435
-
436
391
  fireDrop(dropzone, data);
437
392
 
438
- rerender(ui);
393
+ await flushPromises(rerender, ui);
439
394
 
440
- await waitFor(() => {
441
- expect(
442
- getByText('Upload only files with a maximum size of 1 Bytes.')
443
- ).toBeInTheDocument();
444
- });
395
+ expect(
396
+ getByText('Upload only files with a maximum size of 1 Bytes.')
397
+ ).toBeInTheDocument();
445
398
  });
446
399
 
447
400
  it('shows errors on too small of a file in the file list', async () => {
@@ -453,16 +406,13 @@ describe('File Uploader', () => {
453
406
  const { getByTestId, getByText, rerender } = render(ui);
454
407
 
455
408
  const dropzone = getByTestId(testId);
456
-
457
409
  fireDrop(dropzone, data);
458
410
 
459
- rerender(ui);
411
+ await flushPromises(rerender, ui);
460
412
 
461
- await waitFor(() => {
462
- expect(
463
- getByText('Upload only files with a minimum size of 9.77 KB.')
464
- ).toBeInTheDocument();
465
- });
413
+ expect(
414
+ getByText('Upload only files with a minimum size of 9.77 KB.')
415
+ ).toBeInTheDocument();
466
416
  });
467
417
 
468
418
  it('adds a Spinner to files in progress', async () => {
@@ -477,16 +427,13 @@ describe('File Uploader', () => {
477
427
  const { getByTestId, getByLabelText, getByText, rerender } = render(ui);
478
428
 
479
429
  const dropzone = getByTestId(testId);
480
-
481
430
  fireDrop(dropzone, data);
482
431
 
483
- rerender(ui);
432
+ await flushPromises(rerender, ui);
484
433
 
485
- await waitFor(() => {
486
- expect(getByText(files[0].name)).toBeInTheDocument();
487
- expect(getByText('25%')).toBeInTheDocument();
488
- expect(getByLabelText('Loading')).toBeInTheDocument();
489
- });
434
+ expect(getByText(files[0].name)).toBeInTheDocument();
435
+ expect(getByText('25%')).toBeInTheDocument();
436
+ expect(getByLabelText('Loading')).toBeInTheDocument();
490
437
  });
491
438
 
492
439
  it('shows an error in the file list on error', async () => {
@@ -510,18 +457,14 @@ describe('File Uploader', () => {
510
457
  const { getByTestId, getByText, rerender } = render(ui);
511
458
 
512
459
  const dropzone = getByTestId(testId);
513
-
514
460
  fireDrop(dropzone, data);
515
461
 
516
- rerender(ui);
462
+ await flushPromises(rerender, ui);
517
463
 
518
- await waitFor(() => {
519
- expect(getByText('error from the processor')).toBeInTheDocument();
520
- });
464
+ expect(getByText('error from the processor')).toBeInTheDocument();
521
465
  });
522
466
 
523
- // TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
524
- xit('changes to delete file on finish', async () => {
467
+ it('changes to delete file on finish', async () => {
525
468
  const onSendFile = ({ file, onFinish }) => {
526
469
  onFinish({ file });
527
470
  };
@@ -533,23 +476,21 @@ describe('File Uploader', () => {
533
476
  const { getByTestId, getByLabelText, getByText, rerender } = render(ui);
534
477
 
535
478
  const dropzone = getByTestId(testId);
479
+ act(() => fireDrop(dropzone, data));
536
480
 
537
- fireDrop(dropzone, data);
538
-
539
- rerender(ui);
481
+ await flushPromises(rerender, ui);
482
+ await act(() =>
483
+ waitFor(() => getByLabelText(`Delete file ${files[0].name}`))
484
+ );
540
485
 
541
- await waitFor(() => {
542
- expect(getByText(files[0].name)).toBeInTheDocument();
543
- expect(getByLabelText('Delete file')).toBeInTheDocument();
544
- });
486
+ expect(getByText(files[0].name)).toBeInTheDocument();
487
+ expect(getByLabelText(`Delete file ${files[0].name}`)).toBeInTheDocument();
545
488
  });
546
489
 
547
- // TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
548
- xit('deletes the file when the Delete File icon is clicked', async () => {
490
+ it('deletes the file when the Delete File icon is clicked', async () => {
549
491
  const onSendFile = ({ file, onFinish }) => {
550
492
  onFinish({ file });
551
493
  };
552
-
553
494
  const data = createDtWithFiles(files);
554
495
  const testId = 'testId';
555
496
 
@@ -559,27 +500,23 @@ describe('File Uploader', () => {
559
500
  render(ui);
560
501
 
561
502
  const dropzone = getByTestId(testId);
562
- fireDrop(dropzone, data);
503
+ act(() => fireDrop(dropzone, data));
563
504
 
564
- rerender(ui);
565
-
566
- await waitFor(() => {
567
- expect(getByText(files[0].name)).toBeInTheDocument();
568
- });
569
-
570
- const deleteIcon = getByLabelText('Delete file');
505
+ await flushPromises(rerender, ui);
506
+ await act(() =>
507
+ waitFor(() => getByLabelText(`Delete file ${files[0].name}`))
508
+ );
571
509
 
572
- await userEvent.click(deleteIcon);
510
+ expect(getByText(files[0].name)).toBeInTheDocument();
511
+ const deleteIcon = getByLabelText(`Delete file ${files[0].name}`);
573
512
 
574
- rerender(ui);
513
+ userEvent.click(deleteIcon);
575
514
 
576
- await waitFor(() => {
577
- expect(queryByText(files[0].name)).not.toBeInTheDocument();
578
- });
515
+ await flushPromises(rerender, ui);
516
+ expect(queryByText(files[0].name)).not.toBeInTheDocument();
579
517
  });
580
518
 
581
- // TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
582
- xit('calls onDeleteFile when the Delete File icon is clicked', async () => {
519
+ it('calls onDeleteFile when the Delete File icon is clicked', async () => {
583
520
  const onDeleteFileSpy = jest.fn();
584
521
  const onSendFile = ({ file, onFinish }) => {
585
522
  onFinish({ file });
@@ -599,24 +536,20 @@ describe('File Uploader', () => {
599
536
  const { getByTestId, getByLabelText, getByText, rerender } = render(ui);
600
537
 
601
538
  const dropzone = getByTestId(testId);
539
+ act(() => fireDrop(dropzone, data));
602
540
 
603
- fireDrop(dropzone, data);
604
-
605
- rerender(ui);
606
-
607
- await waitFor(() => {
608
- expect(getByText(files[0].name)).toBeInTheDocument();
609
- });
610
-
611
- const deleteIcon = getByLabelText('Delete file');
541
+ await flushPromises(rerender, ui);
542
+ await act(() =>
543
+ waitFor(() => getByLabelText(`Delete file ${files[0].name}`))
544
+ );
612
545
 
613
- await userEvent.click(deleteIcon);
546
+ expect(getByText(files[0].name)).toBeInTheDocument();
547
+ const deleteIcon = getByLabelText(`Delete file ${files[0].name}`);
614
548
 
615
- rerender(ui);
549
+ userEvent.click(deleteIcon);
616
550
 
617
- await waitFor(() => {
618
- expect(onDeleteFileSpy).toHaveBeenCalledTimes(1);
619
- });
551
+ await flushPromises(rerender, ui);
552
+ expect(onDeleteFileSpy).toHaveBeenCalledTimes(1);
620
553
  });
621
554
 
622
555
  it('removes the file when the Remove File icon is clicked', async () => {
@@ -628,7 +561,6 @@ describe('File Uploader', () => {
628
561
  const { getByTestId, getByLabelText, queryByText, rerender } = render(ui);
629
562
 
630
563
  const dropzone = getByTestId(testId);
631
-
632
564
  fireDrop(dropzone, data);
633
565
 
634
566
  rerender(ui);
@@ -637,15 +569,12 @@ describe('File Uploader', () => {
637
569
  expect(queryByText(files[0].name)).toBeInTheDocument();
638
570
  });
639
571
 
640
- const removeIcon = getByLabelText('Remove file');
641
-
642
- await userEvent.click(removeIcon);
572
+ const removeIcon = getByLabelText(`Remove file ${files[0].name}`);
643
573
 
644
- rerender(ui);
574
+ userEvent.click(removeIcon);
645
575
 
646
- await waitFor(() => {
647
- expect(queryByText(files[0].name)).not.toBeInTheDocument();
648
- });
576
+ await flushPromises(rerender, ui);
577
+ expect(queryByText(files[0].name)).not.toBeInTheDocument();
649
578
  });
650
579
 
651
580
  it('calls onRemoveFile when the Remove File icon is clicked', async () => {
@@ -658,20 +587,16 @@ describe('File Uploader', () => {
658
587
  const { getByTestId, findByLabelText, rerender } = render(ui);
659
588
 
660
589
  const dropzone = getByTestId(testId);
661
-
662
590
  fireDrop(dropzone, data);
663
591
 
664
592
  rerender(ui);
665
593
 
666
- const removeIcon = await findByLabelText('Remove file');
667
-
668
- await userEvent.click(removeIcon);
594
+ const removeIcon = await findByLabelText(`Remove file ${files[0].name}`);
669
595
 
670
- rerender(ui);
596
+ userEvent.click(removeIcon);
671
597
 
672
- await waitFor(() => {
673
- expect(onRemoveFileSpy).toHaveBeenCalledTimes(1);
674
- });
598
+ await flushPromises(rerender, ui);
599
+ expect(onRemoveFileSpy).toHaveBeenCalledTimes(1);
675
600
  });
676
601
 
677
602
  it('dropzoneOptions should be passed to Dropzone', async () => {
@@ -683,19 +608,20 @@ describe('File Uploader', () => {
683
608
  const { getByTestId, getAllByText, rerender } = render(ui);
684
609
 
685
610
  const dropzone = getByTestId(testId);
686
-
687
611
  fireDrop(dropzone, data);
688
612
 
689
- rerender(ui);
613
+ await flushPromises(rerender, ui);
690
614
 
691
- await waitFor(() => {
692
- expect(
693
- getAllByText(/You must upload a maximum of/i)[0]
694
- ).toBeInTheDocument();
695
- });
615
+ expect(
616
+ getAllByText(/You must upload a maximum of/i)[0]
617
+ ).toBeInTheDocument();
696
618
  });
697
619
  });
698
620
 
621
+ async function flushPromises(rerender, ui) {
622
+ await act(() => waitFor(() => rerender(ui)));
623
+ }
624
+
699
625
  function createDtWithFiles(files = []) {
700
626
  return {
701
627
  dataTransfer: {