-
Notifications
You must be signed in to change notification settings - Fork 255
Closed
Description
Could someone explain to me the logic behind this line of code: https://github.com/testing-library/user-event/blob/master/src/upload.js#L17 ?
Consider this code snippet:
function handleChooseImage(event: ChangeEvent<HTMLInputElement>) {
const selectedFiles = event.target.files
if (!selectedFiles?.length) return
...
}
<input
data-testid="add-photos-input"
ref={inputRef}
type="file"
onChange={handleChooseImage}
accept="image/*"
multiple
hidden
/>
My goal is to write following lines of test code
const imageFile = new File([], 'imgname', { type: 'image/png' })
const imageInput = screen.getByTestId('add-photos-input')
userEvent.upload(imageInput, imageFile)
This test code result in event handler being called with an object, where length is undefined and item() returns undefined:
selectedFiles: { length: undefined, item: [Function: item] }
Is that expected behaviour?
justasam
Metadata
Metadata
Assignees
Labels
No labels