Skip to content

Commit 99a42c1

Browse files
committed
Add support for file inputs
1 parent 65bdf07 commit 99a42c1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/__tests__/fire-event.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,20 @@ test('fireEvent.update does not crash if non-input element is passed in', async
231231

232232
expect(console.warn).not.toHaveBeenCalled()
233233
})
234+
235+
test('fireEvent.update handles input file', async () => {
236+
const {getByTestId} = render({
237+
template: `<input type="file" data-testid="test-update" />`,
238+
})
239+
240+
const file = new File(['(⌐□_□)'], 'chucknorris.png', {type: 'image/png'})
241+
242+
const inputEl = getByTestId('test-update')
243+
244+
// You could replace the lines below with
245+
// userEvent.upload(inputEl, file)
246+
Object.defineProperty(inputEl, 'files', {value: [file]})
247+
await fireEvent.update(inputEl)
248+
249+
expect(console.warn).not.toHaveBeenCalled()
250+
})

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ fireEvent.update = (elem, value) => {
170170
if (['checkbox', 'radio'].includes(type)) {
171171
elem.checked = true
172172
return fireEvent.change(elem)
173+
} else if (type === 'file') {
174+
return fireEvent.change(elem)
173175
} else {
174176
elem.value = value
175177
return fireEvent.input(elem)

0 commit comments

Comments
 (0)