Skip to content

Commit 1ad37b4

Browse files
committed
Update based on suggestion
1 parent aec4fcd commit 1ad37b4

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

src/__tests__/fire-event.js

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,6 @@ const eventTypes = [
120120
},
121121
]
122122

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-
134123
beforeEach(() => {
135124
jest.spyOn(console, 'warn').mockImplementation(() => {})
136125
})
@@ -228,28 +217,22 @@ test('fireEvent.update does not trigger warning messages', async () => {
228217
})
229218

230219
test('fireEvent.update should not crash with input file', async () => {
231-
const spy = jest.fn()
232-
233220
const {getByTestId} = render({
234-
render(h) {
235-
return h('input', {
236-
on: {
237-
change: spy,
238-
},
239-
attrs: {
240-
type: 'file',
241-
'data-testid': 'test-update',
242-
},
243-
})
244-
},
221+
template: `<input type="file" data-testid="test-update" />`,
245222
})
246223

247-
// should expect an array of list since it's a fileList
248-
await fireEvent.update(getByTestId('test-update'), [
249-
mockFile({name: 'random.txt', size: 524288}),
250-
])
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)
251235

252-
expect(spy).toHaveBeenCalledTimes(1)
253236
expect(console.warn).not.toHaveBeenCalled()
254237
})
255238

src/vue-testing-library.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ fireEvent.update = (elem, value) => {
156156
elem.checked = true
157157
return fireEvent.change(elem)
158158
} else if (type === 'file') {
159-
Object.defineProperty(elem, 'files', {value})
160159
return fireEvent.change(elem)
161160
} else {
162161
elem.value = value

0 commit comments

Comments
 (0)