Skip to content

Commit 0ed8b64

Browse files
committed
add input file fail test
1 parent a5bd6cc commit 0ed8b64

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/__tests__/fire-event.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ const eventTypes = [
119119
elementType: 'div',
120120
},
121121
]
122+
123+
const mockFile = ({
124+
name,
125+
size = 0,
126+
type = 'text/plain',
127+
lastModified = new Date()
128+
}) => {
129+
const blob = new Blob(['0'.repeat(size)], { type });
130+
blob.lastModifiedDate = lastModified;
131+
return new File([blob], name);
132+
};
133+
122134
beforeEach(() => {
123135
jest.spyOn(console, 'warn').mockImplementation(() => {})
124136
})
@@ -215,6 +227,25 @@ test('fireEvent.update does not trigger warning messages', async () => {
215227
expect(console.warn).not.toHaveBeenCalled()
216228
})
217229

230+
test('fireEvent.update should not crash with input file', async () => {
231+
const inputSpy = jest.fn();
232+
const changeSpy = jest.fn();
233+
234+
const {getByTestId} = render({
235+
template: `<input type="file" @change="$emit('change', $event)" @input="$emit('input, $event)" data-testid=test-update></input>`,
236+
}, {
237+
on: {
238+
input: inputSpy,
239+
change: changeSpy
240+
}
241+
})
242+
243+
// should expect a array of list since it's a fileList
244+
await fireEvent.update(getByTestId('test-update'), [mockFile({ name: 'random.txt', size: 524288 })])
245+
246+
expect(console.warn).not.toHaveBeenCalled()
247+
})
248+
218249
test('fireEvent.update does not crash if non-input element is passed in', async () => {
219250
const {getByText} = render({
220251
template: `<div>Hi</div>`,

0 commit comments

Comments
 (0)