mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
Fix beforeUpload will stop uploading when return (#7870)
value is undefined it should be same as rc-upload
This commit is contained in:
parent
b77cc6392e
commit
43362de756
@ -223,13 +223,13 @@ export default class Upload extends React.Component<UploadProps, any> {
|
||||
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<any>).then) {
|
||||
} else if (result && (result as PromiseLike<any>).then) {
|
||||
return result;
|
||||
}
|
||||
return true;
|
||||
|
@ -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(
|
||||
<Upload {...props}>
|
||||
<button>upload</button>
|
||||
</Upload>
|
||||
);
|
||||
|
||||
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(
|
||||
<Upload {...props}>
|
||||
<button>upload</button>
|
||||
</Upload>
|
||||
);
|
||||
|
||||
wrapper.find('input').simulate('change', {
|
||||
target: {
|
||||
files: [
|
||||
{ filename: 'foo.png' },
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user