-
Notifications
You must be signed in to change notification settings - Fork 113
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 2 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 |
|---|---|---|
|
|
@@ -119,6 +119,18 @@ const eventTypes = [ | |
| elementType: 'div', | ||
| }, | ||
| ] | ||
|
|
||
| const mockFile = ({ | ||
| name, | ||
| size = 0, | ||
| type = 'text/plain', | ||
| lastModified = new Date() | ||
| }) => { | ||
| const blob = new Blob(['0'.repeat(size)], { type }); | ||
| blob.lastModifiedDate = lastModified; | ||
| return new File([blob], name); | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.spyOn(console, 'warn').mockImplementation(() => {}) | ||
| }) | ||
|
|
@@ -215,6 +227,31 @@ test('fireEvent.update does not trigger warning messages', async () => { | |
| expect(console.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('fireEvent.update should not crash with input file', async () => { | ||
|
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. Is this test example not enough? @afontcu 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. It is! But as mentioned, I wouldn't make test('fireEvent.update should not crash with input file', async () => { const {getByTestId} = render({ template: `<input type="file" data-testid="test-update" />` }) const file = new File(['(⌐□しろいしかく_□しろいしかく)'], 'chucknorris.png', { type: 'image/png' }) const inputEl = getByTestId('test-update') Object.defineProperty(inputEl, 'files', { value: [file], }) await fireEvent.update(inputEl) expect(console.warn).not.toHaveBeenCalled() }) 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. I added a suggestion with the change I mention above 👍 |
||
| const inputSpy = jest.fn(); | ||
| const changeSpy = jest.fn(); | ||
|
|
||
| const {getByTestId} = render({ | ||
| render(h) { | ||
| return h('input', { | ||
| on: { | ||
| input: inputSpy, | ||
| change: changeSpy | ||
| }, | ||
| attrs: { | ||
| type: 'file', | ||
| 'data-testid': 'test-update', | ||
| }, | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| // should expect a array of list since it's a fileList | ||
| await fireEvent.update(getByTestId('test-update'), [mockFile({ name: 'random.txt', size: 524288 })]) | ||
|
|
||
| expect(console.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('fireEvent.update does not crash if non-input element is passed in', async () => { | ||
| const {getByText} = render({ | ||
| template: `<div>Hi</div>`, | ||
|
|
||