Skip to content

Commit

Permalink
fix(useUpload): imporve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nemo-shen committed Feb 16, 2024
1 parent 79c6448 commit cb98850
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 9 additions & 0 deletions packages/core/useUpload/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ describe('useUpload', () => {
'image-jpg',
'image-png1',
])

const { files: files2, append: append2 } = useUpload({
url: '#',
accept: '.png',
})
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.')
})

test('max-count', async () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/core/useUpload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ export const useUpload = (options: UseUploadOptions): UseUploadReturn => {

const append = async (file: File | File[] | FileList) => {
let appendFiles = []
if (file instanceof FileList) {
if ('length' in file) {
appendFiles = Array.from(file)
} else if (Array.isArray(file)) {
appendFiles = file
} else if (file instanceof File) {
appendFiles = [file]
}
Expand Down

0 comments on commit cb98850

Please sign in to comment.