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 { 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', () => {
let wrapper;
afterEach(() => {
@ -29,59 +40,57 @@ describe('Uploader', () => {
expect(wrapper.vm.onValueChange({ target: { files: [] }})).to.equal(undefined);
});
// it('before read', () => {
// wrapper = mount(Uploader, {
// propsData: {
// disabled: false,
// beforeRead: () => {
// return false;
// }
// }
// });
it('before read', () => {
wrapper = mount(Uploader, {
propsData: {
disabled: false,
beforeRead: () => {
return false;
}
}
});
// expect(wrapper.contains('input')).to.equal(true);
// expect(wrapper.vm.onValueChange({ target: { files: [new File([], '')] }})).to.equal(undefined);
// });
expect(wrapper.contains('input')).to.equal(true);
expect(wrapper.vm.onValueChange({ target: { files: [new File([], '')] }})).to.equal(undefined);
});
// it('read text', () => {
// wrapper = mount(Uploader, {
// propsData: {
// disabled: false,
// resultType: 'text',
// afterRead: (file) => {
// console.log(file);
// }
// }
// });
it('read text', () => {
wrapper = mount(Uploader, {
propsData: {
disabled: false,
resultType: 'text',
afterRead: (file) => {
}
}
});
// expect(wrapper.contains('input')).to.equal(true);
// expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
// });
expect(wrapper.contains('input')).to.equal(true);
expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
});
// it('read text no after hook', () => {
// wrapper = mount(Uploader, {
// propsData: {
// disabled: false,
// resultType: 'text'
// }
// });
it('read text no after hook', () => {
wrapper = mount(Uploader, {
propsData: {
disabled: false,
resultType: 'text'
}
});
// expect(wrapper.contains('input')).to.equal(true);
// expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
// });
expect(wrapper.contains('input')).to.equal(true);
expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
});
// it('read dataUrl', () => {
// wrapper = mount(Uploader, {
// propsData: {
// disabled: false,
// resultType: 'dataUrl',
// afterRead: (file) => {
// console.log(file);
// }
// }
// });
it('read dataUrl', () => {
wrapper = mount(Uploader, {
propsData: {
disabled: false,
resultType: 'dataUrl',
afterRead: (file) => {
}
}
});
// expect(wrapper.contains('input')).to.equal(true);
// expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
// });
expect(wrapper.contains('input')).to.equal(true);
expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
});
});