{
+ setTimeout(() => {
+ onSuccess(null, file);
+ });
+};
+
+export const errorRequest = ({ onError }) => {
+ setTimeout(() => {
+ onError();
+ });
+};
diff --git a/components/upload/__tests__/uploadlist.test.js b/components/upload/__tests__/uploadlist.test.js
index ba0e07739d..004ac48d4d 100644
--- a/components/upload/__tests__/uploadlist.test.js
+++ b/components/upload/__tests__/uploadlist.test.js
@@ -1,6 +1,7 @@
import React from 'react';
import { mount } from 'enzyme';
import Upload from '..';
+import { errorRequest, successRequest } from './requests';
const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
@@ -62,23 +63,47 @@ describe('Upload List', () => {
it('should be uploading when upload a file', (done) => {
let wrapper;
- let finished;
const onChange = ({ file }) => {
- if (finished) {
- done();
- return;
- }
if (file.status === 'uploading') {
expect(wrapper.render()).toMatchSnapshot();
}
- if (file.status === 'error') {
+ if (file.status === 'done') {
+ expect(wrapper.render()).toMatchSnapshot();
+ done();
+ }
+ };
+ wrapper = mount(
+
+
+
+ );
+ wrapper.find('input').simulate('change', {
+ target: {
+ files: [
+ { filename: 'foo.png' },
+ ],
+ },
+ });
+ });
+
+ it('handle error', (done) => {
+ let wrapper;
+ const onChange = ({ file }) => {
+ if (file.status !== 'uploading') {
expect(wrapper.render()).toMatchSnapshot();
- finished = true;
done();
}
};
wrapper = mount(
-
+
);