add test case

This commit is contained in:
Hal-pan 2019-01-12 18:08:10 +08:00 committed by 偏右
parent 4ac517d610
commit 7c5083f4fa

View File

@ -319,4 +319,53 @@ describe('Upload', () => {
expect(linkNode.props().download).toBe('image');
expect(linkNode.props().rel).toBe('noopener');
});
it('should not stop remove when return value of onRemove is false', () => {
const mockRemove = jest.fn(() => false);
const props = {
onRemove: mockRemove,
fileList: [
{
uid: '-1',
name: 'foo.png',
status: 'done',
url: 'http://www.baidu.com/xxx.png',
},
],
};
const wrapper = mount(<Upload {...props} />);
wrapper.find('div.ant-upload-list-item i.anticon-close').simulate('click');
expect(mockRemove).toBeCalled();
expect(props.fileList).toHaveLength(1);
expect(props.fileList[0].status).toBe('done');
});
it('remove file in onRemove', done => {
const mockRemove = jest.fn();
const props = {
onRemove: mockRemove,
fileList: [
{
uid: '-1',
name: 'foo.png',
status: 'done',
url: 'http://www.baidu.com/xxx.png',
},
],
onChange: ({ file }, fileList) => {
if (file.status === 'removed') {
expect(mockRemove).toBeCalled();
expect(fileList).toHaveLength(0);
done();
}
},
};
const wrapper = mount(<Upload {...props} />);
wrapper.find('div.ant-upload-list-item i.anticon-close').simulate('click');
});
});