upload unit test

This commit is contained in:
cookfront 2017-04-25 17:12:01 +08:00
commit 50f359a420

View File

@ -1,6 +1,17 @@
import Uploader from 'packages/uploader'; import Uploader from 'packages/uploader';
import { mount } from 'avoriaz'; import { mount } from 'avoriaz';
window.File = function() {
this.name = 'test';
};
window.FileReader = function() {
this.readAsDataURL = this.readAsText = function() {
this.onload && this.onload({
target: {
result: 'test'
}
});
};
};
describe('Uploader', () => { describe('Uploader', () => {
let wrapper; let wrapper;
afterEach(() => { afterEach(() => {
@ -29,59 +40,57 @@ describe('Uploader', () => {
expect(wrapper.vm.onValueChange({ target: { files: [] }})).to.equal(undefined); expect(wrapper.vm.onValueChange({ target: { files: [] }})).to.equal(undefined);
}); });
// it('before read', () => { it('before read', () => {
// wrapper = mount(Uploader, { wrapper = mount(Uploader, {
// propsData: { propsData: {
// disabled: false, disabled: false,
// beforeRead: () => { beforeRead: () => {
// return false; return false;
// } }
// } }
// }); });
// expect(wrapper.contains('input')).to.equal(true); expect(wrapper.contains('input')).to.equal(true);
// expect(wrapper.vm.onValueChange({ target: { files: [new File([], '')] }})).to.equal(undefined); expect(wrapper.vm.onValueChange({ target: { files: [new File([], '')] }})).to.equal(undefined);
// }); });
// it('read text', () => { it('read text', () => {
// wrapper = mount(Uploader, { wrapper = mount(Uploader, {
// propsData: { propsData: {
// disabled: false, disabled: false,
// resultType: 'text', resultType: 'text',
// afterRead: (file) => { afterRead: (file) => {
// console.log(file); }
// } }
// } });
// });
// expect(wrapper.contains('input')).to.equal(true); expect(wrapper.contains('input')).to.equal(true);
// expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined); expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
// }); });
// it('read text no after hook', () => { it('read text no after hook', () => {
// wrapper = mount(Uploader, { wrapper = mount(Uploader, {
// propsData: { propsData: {
// disabled: false, disabled: false,
// resultType: 'text' resultType: 'text'
// } }
// }); });
// expect(wrapper.contains('input')).to.equal(true); expect(wrapper.contains('input')).to.equal(true);
// expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined); expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
// }); });
// it('read dataUrl', () => { it('read dataUrl', () => {
// wrapper = mount(Uploader, { wrapper = mount(Uploader, {
// propsData: { propsData: {
// disabled: false, disabled: false,
// resultType: 'dataUrl', resultType: 'dataUrl',
// afterRead: (file) => { afterRead: (file) => {
// console.log(file); }
// } }
// } });
// });
// expect(wrapper.contains('input')).to.equal(true); expect(wrapper.contains('input')).to.equal(true);
// expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined); expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
// }); });
}); });