diff --git a/components/upload/Upload.tsx b/components/upload/Upload.tsx index 47b1c23b7e..afa028d4a1 100644 --- a/components/upload/Upload.tsx +++ b/components/upload/Upload.tsx @@ -223,13 +223,13 @@ export default class Upload extends React.Component { return true; } const result = this.props.beforeUpload(file, fileList); - if (!result) { + if (result === false) { this.onChange({ file, fileList, }); return false; - } else if ((result as PromiseLike).then) { + } else if (result && (result as PromiseLike).then) { return result; } return true; diff --git a/components/upload/__tests__/upload.test.js b/components/upload/__tests__/upload.test.js index b28e514202..5afd0d5b77 100644 --- a/components/upload/__tests__/upload.test.js +++ b/components/upload/__tests__/upload.test.js @@ -53,4 +53,58 @@ describe('Upload', () => { }, }); }); + + it('should not stop upload when return value of beforeUpload is not false', (done) => { + const data = jest.fn(); + const props = { + action: 'http://upload.com', + beforeUpload: () => false, + data, + onChange: () => { + expect(data).not.toBeCalled(); + done(); + }, + }; + + const wrapper = mount( + + + + ); + + wrapper.find('input').simulate('change', { + target: { + files: [ + { filename: 'foo.png' }, + ], + }, + }); + }); + + it('should not stop upload when return value of beforeUpload is not false', (done) => { + const data = jest.fn(); + const props = { + action: 'http://upload.com', + beforeUpload() {}, + data, + onChange: () => { + expect(data).toBeCalled(); + done(); + }, + }; + + const wrapper = mount( + + + + ); + + wrapper.find('input').simulate('change', { + target: { + files: [ + { filename: 'foo.png' }, + ], + }, + }); + }); });