Skip to content
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

fix(upload): apply changeInit correctly #670

Merged
merged 3 commits into from Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/__tests__/upload.js
Expand Up @@ -251,3 +251,15 @@ test('throw error if trying to use upload on an invalid element', () => {
`"The associated INPUT element does not accept file uploads"`,
)
})

test('apply init options', () => {
const {element, getEvents} = setup('<input type="file"/>')

userEvent.upload(element, new File([], 'hello.png'), {
clickInit: {shiftKey: true},
changeInit: {cancelable: true},
})

expect(getEvents('click')[0]).toHaveProperty('shiftKey', true)
expect(getEvents('change')[0]).toHaveProperty('cancelable', true)
})
5 changes: 2 additions & 3 deletions src/upload.ts
Expand Up @@ -6,7 +6,7 @@ import {isDisabled, isElementType} from './utils'

interface uploadInit {
clickInit?: MouseEventInit
changeInit?: Event
changeInit?: EventInit
}

interface uploadOptions {
Expand Down Expand Up @@ -74,13 +74,12 @@ function upload(
bubbles: true,
cancelable: false,
composed: true,
...init,
}),
)

fireEvent.change(input, {
target: {files: inputFiles},
...init,
...init?.changeInit,
})
}

Expand Down