Skip to content

Commit

Permalink
fix(upload): apply changeInit correctly (#670)
Browse files Browse the repository at this point in the history
* fix(upload): apply changeInit correctly

* test: apply init options
  • Loading branch information
ph-fritsche authored Apr 29, 2021
1 parent 557caaf commit de09b1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/__tests__/upload.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit de09b1b

Please # to comment.