Skip to content

Commit

Permalink
fix(useUpload): improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nemo-shen committed Feb 16, 2024
1 parent cb98850 commit b3bbfff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions packages/core/useUpload/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion src/demo/UseUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b3bbfff

Please sign in to comment.