@@ -120,17 +120,6 @@ const eventTypes = [
120
120
} ,
121
121
]
122
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
-
134
123
beforeEach ( ( ) => {
135
124
jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
136
125
} )
@@ -228,28 +217,22 @@ test('fireEvent.update does not trigger warning messages', async () => {
228
217
} )
229
218
230
219
test ( 'fireEvent.update should not crash with input file' , async ( ) => {
231
- const spy = jest . fn ( )
232
-
233
220
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" />` ,
245
222
} )
246
223
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 )
251
235
252
- expect ( spy ) . toHaveBeenCalledTimes ( 1 )
253
236
expect ( console . warn ) . not . toHaveBeenCalled ( )
254
237
} )
255
238
0 commit comments