/* 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 (
);
}
}
mount();
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(
);
wrapper.find('input').simulate('change', {
target: {
files: [
{ filename: 'foo.png' },
],
},
});
});
});