Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b762198

Browse files
JeromeDeLeonafontcu
andauthored
feat: Add support for input file on fireEvent.update (#179)
* add input file fail test * fix incorrect render * add input file to update fireEvent * Update based on suggestion Co-authored-by: Adrià Fontcuberta <afontcu@gmail.com>
1 parent a051013 commit b762198

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

‎src/__tests__/fire-event.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ const eventTypes = [
119119
elementType: 'div',
120120
},
121121
]
122+
122123
beforeEach(() => {
123124
jest.spyOn(console, 'warn').mockImplementation(() => {})
124125
})
@@ -215,6 +216,26 @@ test('fireEvent.update does not trigger warning messages', async () => {
215216
expect(console.warn).not.toHaveBeenCalled()
216217
})
217218

219+
test('fireEvent.update should not crash with input file', async () => {
220+
const {getByTestId} = render({
221+
template: `<input type="file" data-testid="test-update" />`,
222+
})
223+
224+
const file = new File(['(⌐しろいしかく_しろいしかく)'], 'chucknorris.png', {type: 'image/png'})
225+
226+
const inputEl = getByTestId('test-update')
227+
228+
// You could replace the lines below with
229+
// userEvent.upload(inputEl, file)
230+
Object.defineProperty(inputEl, 'files', {
231+
value: [file],
232+
})
233+
234+
await fireEvent.update(inputEl)
235+
236+
expect(console.warn).not.toHaveBeenCalled()
237+
})
238+
218239
test('fireEvent.update does not crash if non-input element is passed in', async () => {
219240
const {getByText} = render({
220241
template: `<div>Hi</div>`,

‎src/vue-testing-library.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ fireEvent.update = (elem, value) => {
158158
if (['checkbox', 'radio'].includes(type)) {
159159
elem.checked = true
160160
return fireEvent.change(elem)
161+
} else if (type === 'file') {
162+
return fireEvent.change(elem)
161163
} else {
162164
elem.value = value
163165
if (elem._vModifiers && elem._vModifiers.lazy) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /