mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-02 15:59:38 +08:00
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
/* eslint-disable react/no-string-refs, react/prefer-es6-class */
|
|
import React from 'react';
|
|
import { mount } from 'enzyme';
|
|
import Upload from '..';
|
|
|
|
describe('Upload', () => {
|
|
// https://github.com/react-component/upload/issues/36
|
|
it('should get refs inside Upload in componentDidMount', () => {
|
|
let ref;
|
|
class App extends React.Component {
|
|
componentDidMount() {
|
|
ref = this.refs.input;
|
|
}
|
|
render() {
|
|
return (
|
|
<Upload supportServerRender={false}>
|
|
<input ref="input" />
|
|
</Upload>
|
|
);
|
|
}
|
|
}
|
|
mount(<App />);
|
|
expect(ref).toBeDefined();
|
|
});
|
|
|
|
it('return promise in beforeUpload', (done) => {
|
|
const data = jest.fn();
|
|
const props = {
|
|
action: 'http://upload.com',
|
|
beforeUpload: () => new Promise(resolve =>
|
|
setTimeout(() => resolve('success'))
|
|
),
|
|
data,
|
|
onChange: ({ file }) => {
|
|
if (file.status !== 'uploading') {
|
|
expect(data).toBeCalled();
|
|
done();
|
|
}
|
|
},
|
|
};
|
|
|
|
const wrapper = mount(
|
|
<Upload {...props}>
|
|
<button>upload</button>
|
|
</Upload>
|
|
);
|
|
|
|
wrapper.find('input').simulate('change', {
|
|
target: {
|
|
files: [
|
|
{ filename: 'foo.png' },
|
|
],
|
|
},
|
|
});
|
|
});
|
|
});
|