feat(Uploader): use before read promise resolved value (#5813)

This commit is contained in:
Pingren Nie
2020-03-12 20:52:25 +08:00
committed by GitHub
parent df877751b3
commit e96c352680
5 changed files with 49 additions and 165 deletions

View File

@@ -118,7 +118,7 @@ it('before read return promise and resolve', async () => {
propsData: {
beforeRead: () =>
new Promise(resolve => {
resolve();
resolve(file);
}),
afterRead,
},
@@ -130,6 +130,25 @@ it('before read return promise and resolve', async () => {
expect(afterRead).toHaveBeenCalledTimes(1);
});
it('before read return promise and resolve no value', async () => {
const afterRead = jest.fn();
const wrapper = mount(Uploader, {
propsData: {
beforeRead: () =>
new Promise(resolve => {
resolve();
}),
afterRead,
},
});
const input = wrapper.find('input');
wrapper.vm.onChange(file);
await later();
expect(afterRead).toHaveBeenCalledTimes(1);
expect(input.element.value).toEqual('');
});
it('before read return promise and reject', async () => {
const afterRead = jest.fn();
const wrapper = mount(Uploader, {
@@ -143,9 +162,9 @@ it('before read return promise and reject', async () => {
});
const input = wrapper.find('input');
wrapper.vm.onChange(file);
await later();
wrapper.vm.onChange(file);
expect(afterRead).toHaveBeenCalledTimes(0);
expect(input.element.value).toEqual('');
});