-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with new native event test helpers in Ember 2.5.1 #13540
Comments
To follow up on this here are some Ember Twiddles I have made showing the failing tests as very simple use cases. Working both in Ember 2.4.3 acceptance tests and in browser example File Chooser Tests - Ember 2.4.5 Working only in browser for both jQuery and native events in Ember 2.5.1 |
@cibernox - Would you mind taking a look? |
I stand corrected, this appeared in 2.5.0. That PR is clear. |
Ok @chrism , after some digging, I have bad news and a workaround. One difference between native events and jquery events, is that in native events, the I tried to append the file to the input for real using Basically, the entire web platform conspires to prevent mocking of file inputs. I guess that it's because of security concerns. The solution I've found changing application code a little bit is this: https://github.com/cibernox/__simulate_file_upload_example/blob/master/app/templates/components/file-chooser.hbs#L1 |
Hi @cibernox — firstly a massive thank you for looking into this. As I already have one or two places in my application code where I’ve had to do something similar a work around like this isn’t such a big deal. For me the main issue was knowing where to look for advice on this as it doesn’t quite fall in any of the obvious places. On this hopefully I might be able to help — I'm going to update my Ember Twiddles with working versions following your format and write a blog post on how to write acceptance tests for file uploads. Once I have, if you don’t mind, I’d appreciate you casting your eye over it to make sure I am giving sound advice. Once again thanks for your help on this, it’s very much appreciated. |
Yes, I agree this was a bit of a difficult one to diagnose.
Sounds great, thank you! |
@chrism sure, just ping me in slack whenever you want me to take a look. |
@cibernox i'm on slack if you want to reply there but thought i'd post the URL here too for others. thanks again for your help |
no issue - override `x-file-input` in `gh-file-input` to look for a custom property on the change event if we are in testing mode (this is necessary because Ember 2.5+ use native rather than jQuery events so `target.files` is readonly, see emberjs/ember.js#13540) - migrate unit tests for the uploader components to the integration tests - add skipped acceptance tests for the subscribers CSV import now that it's possible to simulate file uploads
no issue - override `x-file-input` in `gh-file-input` to look for a custom property on the change event if we are in testing mode (this is necessary because Ember 2.5+ use native rather than jQuery events so `target.files` is readonly, see emberjs/ember.js#13540) - migrate unit tests for the uploader components to the integration tests - add skipped acceptance tests for the subscribers CSV import now that it's possible to simulate file uploads
no issue - override `x-file-input` in `gh-file-input` to look for a custom property on the change event if we are in testing mode (this is necessary because Ember 2.5+ use native rather than jQuery events so `target.files` is readonly, see emberjs/ember.js#13540) - migrate unit tests for the uploader components to the integration tests - add skipped acceptance tests for the subscribers CSV import now that it's possible to simulate file uploads
Prior to upgrading to 2.5 my acceptance tests worked for mocking file uploads by using jQuery events on my component. eg
Working in 2.4.3
file-chooser.hbs
file-chooser.js
My custom test helper which allowed me to successfully add a file via
uploadFile('#file-chooser', ['test text'], {});
Unfortunately this approach no longer seems to work in 2.5.1 so I have tried updating the component to use native events now instead, but this still is no longer working in acceptance tests
Not Working in 2.5.1
file-chooser.hbs
file-chooser.js
With the same test helper.
This approach works fine in the browser outside of tests (as did the jQuery version). But the test shows an empty
FileList
array forevent.target.files
now.I notice from the release notes that this has been a change in Ember 2.5.1
Is this a regression, or have I misunderstood how to create a file chooser mockable in an acceptance test?
The text was updated successfully, but these errors were encountered: