Uploading a file in an Ember test

Last reviewed on March 21, 2024

For the longest time I didn't think it was possible to upload a file in an Ember integration test or acceptance test because clicking on a file input opens the browser's native file picker which can't be interacted with since it isn't in the DOM.

However, today I learned of a workaround where triggerEvent from @ember/test-helpers can be used to simulate picking a file.

await triggerEvent('input[type="file"]', "change", {
  files: [new File(["File contents here"], "file-to-upload.txt")],