-
Notifications
You must be signed in to change notification settings - Fork 111
Add support for input file on fireEvent.update
#179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
0ed8b64
bfaeee7
aec4fcd
9933d00
1ad37b4
c167d1e
06eced1
f408a45
59e3946
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -155,6 +155,9 @@ fireEvent.update = (elem, value) => { | |||||||||||
if (['checkbox', 'radio'].includes(type)) { | ||||||||||||
elem.checked = true | ||||||||||||
return fireEvent.change(elem) | ||||||||||||
} else if (type === 'file') { | ||||||||||||
Object.defineProperty(elem, 'files', {value}) | ||||||||||||
return fireEvent.change(elem) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(also not 100% sure if we should trigger a change event over an input one? 🤔 haven't checked, so it might be okay) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems pretty okay to me since we know we can't use v-model to an input file and the only reasonable event to use in this case is change. |
||||||||||||
} else { | ||||||||||||
elem.value = value | ||||||||||||
return fireEvent.input(elem) | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this test example not enough? @afontcu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is! But as mentioned, I wouldn't make
fireEvent.update()
smarter when it comes to type="file" inputs. I would just trigger the proper event, and then add a test showcasing how to handle files as in React Testing Library (and probably also a comment suggesting userEvent to do so:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a suggestion with the change I mention above 👍