Acceptance Testing File Uploads in Ember 2.5+

Prior to Ember 2.5

Before 2.5 it was possible to test file uploads by mocking the event directly:

A working example on Ember Twiddle

In this example the jQuery events allow for target to be written, passing in your mock files.

Issue with File Upload Tests in Ember 2.5+

Ember 2.5 introduced native events in testing, which is great news as it allows non-jQuery events to now be triggered in tests but one side-effect of this is that event.target is now read-only.

You can see from these examples, both using jQuery events and native events, that files are no longer passed into the event.

A non-working example on Ember Twiddle using jQuery events

A non-working example on Ember Twiddle using native events

Solution and Working Example

Unfortunately it involves a very minor change to application code now to get the tests passing, but the solution is very straightforward.

Instead of trying to override the event.target, which is disallowed by the spec, we pass the files in a testingFiles property and use a conditional to use that property instead when the app is in testing mode.

A working example on Ember Twiddle

You can read the full Ember issue here.

Many thanks to @MiguelCamba for his help solving this.