diff --git a/src/__tests__/upload.js b/src/__tests__/upload.js index f57c116b..37640cf3 100644 --- a/src/__tests__/upload.js +++ b/src/__tests__/upload.js @@ -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('') + + 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) +}) diff --git a/src/upload.ts b/src/upload.ts index 04a79bb7..5837ae26 100644 --- a/src/upload.ts +++ b/src/upload.ts @@ -6,7 +6,7 @@ import {isDisabled, isElementType} from './utils' interface uploadInit { clickInit?: MouseEventInit - changeInit?: Event + changeInit?: EventInit } interface uploadOptions { @@ -74,13 +74,12 @@ function upload( bubbles: true, cancelable: false, composed: true, - ...init, }), ) fireEvent.change(input, { target: {files: inputFiles}, - ...init, + ...init?.changeInit, }) }