Skip to content

Commit 499043a

Browse files
author
lh01217311
committed
test: add tests for async action/data rejection in retryUpload
- Add test for async action rejection - Add test for async data rejection
1 parent 4f60d5f commit 499043a

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

tests/uploader.spec.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,67 @@ describe('uploader', () => {
279279
}, 100);
280280
});
281281

282+
it('retryUpload should not make request when async action rejects', done => {
283+
const uploadRef = React.createRef<any>();
284+
render(
285+
<Upload
286+
ref={uploadRef}
287+
action={async () => {
288+
throw new Error('action error');
289+
}}
290+
/>,
291+
);
292+
293+
const file = {
294+
uid: 'rc-upload-retry-action-reject',
295+
name: 'retry.png',
296+
toString() {
297+
return this.name;
298+
},
299+
};
300+
301+
const initialRequestCount = requests.length;
302+
303+
uploadRef.current.retryUpload(file as RcFile);
304+
305+
setTimeout(() => {
306+
// Should not make a new request when action rejects
307+
expect(requests.length).toBe(initialRequestCount);
308+
done();
309+
}, 100);
310+
});
311+
312+
it('retryUpload should not make request when async data rejects', done => {
313+
const uploadRef = React.createRef<any>();
314+
render(
315+
<Upload
316+
ref={uploadRef}
317+
action="/test"
318+
data={async () => {
319+
throw new Error('data error');
320+
}}
321+
/>,
322+
);
323+
324+
const file = {
325+
uid: 'rc-upload-retry-data-reject',
326+
name: 'retry.png',
327+
toString() {
328+
return this.name;
329+
},
330+
};
331+
332+
const initialRequestCount = requests.length;
333+
334+
uploadRef.current.retryUpload(file as RcFile);
335+
336+
setTimeout(() => {
337+
// Should not make a new request when data rejects
338+
expect(requests.length).toBe(initialRequestCount);
339+
done();
340+
}, 100);
341+
});
342+
282343
it('drag to upload', done => {
283344
const input = uploader.container.querySelector('input')!;
284345

0 commit comments

Comments
 (0)