Skip to content

Commit

Permalink
fix(VFileInput): filter out values that are not instance of File
Browse files Browse the repository at this point in the history
fixes #10281
  • Loading branch information
johnleider committed Jan 20, 2020
1 parent 55cbdbb commit ebdb4f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 1 addition & 3 deletions packages/vuetify/src/components/VFileInput/VFileInput.ts
Expand Up @@ -95,9 +95,7 @@ export default VTextField.extend({
)
},
internalArrayValue (): File[] {
return Array.isArray(this.internalValue)
? this.internalValue
: wrapInArray(this.internalValue)
return wrapInArray(this.internalValue).filter(file => file instanceof File)
},
internalValue: {
get (): File[] {
Expand Down
Expand Up @@ -14,8 +14,8 @@ import {
MountOptions,
} from '@vue/test-utils'

const oneMBFile = { name: 'test', size: 1048576 }
const twoMBFile = { name: 'test', size: 2097152 }
const oneMBFile = new File([new ArrayBuffer(1048576)], 'test')
const twoMBFile = new File([new ArrayBuffer(2097152)], 'test')

describe('VFileInput.ts', () => {
type Instance = InstanceType<typeof VFileInput>
Expand Down Expand Up @@ -238,7 +238,7 @@ describe('VFileInput.ts', () => {
})

it('should truncate correctly', async () => {
const fifteenCharFile = { name: 'testFile15Chars', size: 1 }
const fifteenCharFile = new File(['V'.repeat(15)], 'testFile15Chars')
const wrapper = mountFunction({
propsData: {
truncateLength: 1,
Expand Down Expand Up @@ -272,4 +272,16 @@ describe('VFileInput.ts', () => {

expect(wrapper.find('.v-file-input__text').text()).toBe('test…hars')
})

it('should filter internal array values for instanceof File', () => {
const wrapper = mountFunction()

const values = [null, undefined, {}, [null], [undefined], [{}]]

for (const value of values) {
wrapper.setProps({ value })

expect(wrapper.vm.internalArrayValue).toEqual([])
}
})
})

0 comments on commit ebdb4f6

Please sign in to comment.