From b3bbfffe63c22c568f69ea32cc5c31617cdcaa02 Mon Sep 17 00:00:00 2001 From: Nemo Date: Fri, 16 Feb 2024 20:03:05 +0800 Subject: [PATCH] fix(useUpload): improve test coverage --- packages/core/useUpload/index.test.ts | 13 ++++++++++--- src/demo/UseUpload.vue | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/core/useUpload/index.test.ts b/packages/core/useUpload/index.test.ts index a3b392a..bb1443f 100644 --- a/packages/core/useUpload/index.test.ts +++ b/packages/core/useUpload/index.test.ts @@ -104,19 +104,24 @@ describe('useUpload', () => { }) test('limit file type', async () => { - const { files, append } = useUpload({ url: '#', accept: 'image/*' }) + const { files, append } = useUpload({ + url: '#', + accept: 'image/*,text/plain', + }) await append(new File([''], 'image-jpg.jpg', { type: 'image/jpg' })) await append(new File([''], 'image-png1.png', { type: 'image/png' })) expect( append(new File([''], 'image-png2.png', { type: '.png' })) ).rejects.toThrow('Invalid file type.') + await append(new File([''], 'file1.txt', { type: 'text/plain' })) expect( - append(new File([''], 'file1.txt', { type: 'text/plain' })) + append(new File([''], 'video.mp4', { type: 'video/mp4' })) ).rejects.toThrow('Invalid file type.') expect(files.value.map((file) => file.name)).toEqual([ 'image-jpg', 'image-png1', + 'file1', ]) const { files: files2, append: append2 } = useUpload({ @@ -126,7 +131,9 @@ describe('useUpload', () => { expect( append2(new File([''], 'image-jpg.jpg', { type: 'image/jpg' })) ).rejects.toThrow('Invalid file type.') - expect(append2(new File([''], 'image-png1.png', { type: 'image/png' }))).rejects.toThrow('Invalid file type.') + expect( + append2(new File([''], 'image-png1.png', { type: 'image/png' })) + ).rejects.toThrow('Invalid file type.') }) test('max-count', async () => { diff --git a/src/demo/UseUpload.vue b/src/demo/UseUpload.vue index 60a7fe0..9627f99 100644 --- a/src/demo/UseUpload.vue +++ b/src/demo/UseUpload.vue @@ -3,7 +3,7 @@ import { watch, ref, h, VNode } from 'vue' import { useUpload } from '@noi/core' const url = 'https://run.mocky.io/v3/da20c84f-fbe5-4510-8f24-80fa61474790' -const { upload, append, files, remove } = useUpload({ url, maxSize: 100 }) +const { upload, append, files, remove } = useUpload({ url }) const inputChange = (event) => { append(event.target.files)