Created
November 5, 2019 17:19
-
-
Save Sebdevar/5642a6a03f6d9e146ad11a2df60aebfa to your computer and use it in GitHub Desktop.
Test utility function used to create a mock dataTransfer event containing a list of supplied files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates a mock dataTransfer event of the specified type containing the supplied list of files. | |
* | |
* @param {string} eventType The event's type, generally used as a trigger. | |
* @param {File[]} files An array of files to be transfered by the event. | |
*/ | |
export const createMockDataTransferEvent = (eventType: string, files: File[]): Event => { | |
const dataTransferObject = { | |
dataTransfer: { | |
files, | |
items: files.map(file => ({ | |
kind: 'file', | |
type: file.type, | |
getAsFile: () => file, | |
})), | |
types: ['Files'], | |
}, | |
}; | |
const event = new Event(eventType, { bubbles: true }); | |
Object.assign(event, dataTransferObject); | |
return event; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment