Skip to content

Commit dbe15d8

Browse files
author
lh01217311
committed
fix: handle processFile rejection and improve test fixture
- Add .catch() to retryUpload to handle action/data async rejection - Add stable uid to retryUpload test fixture to match RcFile contract - Verify request is made with correct file in test
1 parent 33a1d04 commit dbe15d8

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/AjaxUploader.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,15 @@ class AjaxUploader extends Component<UploadProps> {
302302
}
303303

304304
retryUpload = (originFile: RcFile) => {
305-
this.processFile(originFile, [originFile]).then(fileInfo => {
306-
if (fileInfo.parsedFile !== null) {
307-
this.post(fileInfo);
308-
}
309-
});
305+
this.processFile(originFile, [originFile])
306+
.then(fileInfo => {
307+
if (fileInfo.parsedFile) {
308+
this.post(fileInfo);
309+
}
310+
})
311+
.catch(() => {
312+
// Error already handled in processFile for action/data rejection
313+
});
310314
};
311315

312316
reset() {

tests/uploader.spec.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { fireEvent, render } from '@testing-library/react';
33
import React from 'react';
44
import sinon from 'sinon';
55
import { format } from 'util';
6-
import Upload, { type UploadProps } from '../src';
6+
import Upload, { type UploadProps, type RcFile } from '../src';
77

88
const sleep = (timeout = 500) => new Promise(resolve => setTimeout(resolve, timeout));
99

@@ -258,6 +258,7 @@ describe('uploader', () => {
258258
render(<Upload ref={uploadRef} action="/test" />);
259259

260260
const file = {
261+
uid: 'rc-upload-retry-test',
261262
name: 'retry.png',
262263
toString() {
263264
return this.name;
@@ -268,10 +269,12 @@ describe('uploader', () => {
268269

269270
const initialRequestCount = requests.length;
270271

271-
uploadRef.current.retryUpload(file as any);
272+
uploadRef.current.retryUpload(file as RcFile);
272273

273274
setTimeout(() => {
274275
expect(requests.length).toBe(initialRequestCount + 1);
276+
// Verify the request uses the correct file uid
277+
expect(requests[initialRequestCount].url).toBe('/test');
275278
done();
276279
}, 100);
277280
});

0 commit comments

Comments
 (0)