diff --git a/src/utils/clone-deep.js b/src/utils/clone-deep.js index 1f76dd9e32f..4a7663eef08 100644 --- a/src/utils/clone-deep.js +++ b/src/utils/clone-deep.js @@ -1,4 +1,4 @@ -import { isArray, isPlainObject } from './inspect' +import { isArray, isFile, isPlainObject } from './inspect' import { keys } from './object' export const cloneDeep = (obj, defaultValue = obj) => { @@ -11,5 +11,11 @@ export const cloneDeep = (obj, defaultValue = obj) => { {} ) } + if (isFile(obj)) { + return new File([obj], obj.name, { + lastModified: obj.lastModified, + type: obj.type + }) + } return defaultValue } diff --git a/src/utils/clone-deep.spec.js b/src/utils/clone-deep.spec.js index 6e87407318a..23f84fa5de5 100644 --- a/src/utils/clone-deep.spec.js +++ b/src/utils/clone-deep.spec.js @@ -67,4 +67,12 @@ describe('cloneDeep()', () => { expect(cloneDeep(a).c).toEqual(a.c) expect(cloneDeep(a).c).not.toBe(a.c) }) + + it('should clone files', () => { + const a = new File([1, 2, 3], 'test.txt', { type: 'text/plain' }) + expect(cloneDeep(a)).toEqual(a) + expect(cloneDeep(a)).not.toBe(a) + expect(cloneDeep(a.name)).toEqual(a.name) + expect(cloneDeep(a.type)).toEqual(a.type) + }) })