diff --git a/components/upload/__tests__/upload.test.js b/components/upload/__tests__/upload.test.js index edcc2e40a6..fe7c048777 100644 --- a/components/upload/__tests__/upload.test.js +++ b/components/upload/__tests__/upload.test.js @@ -6,7 +6,7 @@ import produce from 'immer'; import { cloneDeep } from 'lodash'; import Upload from '..'; import Form from '../../form'; -import { getFileItem, removeFileItem } from '../utils'; +import { getFileItem, removeFileItem, isImageUrl } from '../utils'; import { setup, teardown } from './mock'; import { resetWarned } from '../../_util/devWarning'; import mountTest from '../../../tests/shared/mountTest'; @@ -367,6 +367,13 @@ describe('Upload', () => { const targetItem = removeFileItem(file, fileList); expect(targetItem).toBe(null); }); + + it('isImageUrl should work correctly when file.url is null', () => { + const file = { + url: null, + }; + expect(isImageUrl(file)).toBe(true); + }); }); it('should support linkProps as object', () => { diff --git a/components/upload/utils.tsx b/components/upload/utils.tsx index 178d558db6..1499436a1f 100644 --- a/components/upload/utils.tsx +++ b/components/upload/utils.tsx @@ -54,7 +54,7 @@ export const isImageUrl = (file: UploadFile): boolean => { if (file.type && !file.thumbUrl) { return isImageFileType(file.type); } - const url: string = (file.thumbUrl || file.url) as string; + const url: string = (file.thumbUrl || file.url || '') as string; const extension = extname(url); if ( /^data:image\//.test(url) ||