-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Add testing support to file-upload onchange action #25
Add testing support to file-upload onchange action #25
Conversation
Sending through the entire event to the action allows for fake files to be injected when testing. See these links for more info: emberjs/ember.js#13540 https://medium.com/@chrisdmasters/acceptance-testing-file-uploads-in-ember-2-5-1c9c8dbe5368
There's an upload helper I made for this: |
Which I need to document, come to think of it. There's a mirage helper that works in conjunction with this as well: https://github.com/tim-evans/ember-file-upload/tree/master/addon/mirage In import { upload } from 'ember-file-upload/mirage';
export default function () {
this.post('/photos', upload(function (db, response) {
return {
filename: response.name,
filesize: response.size,
type: response.type,
width: response.width,
height: response.height
};
});
}; |
Thanks for the response. I was already using mirage helper to mock out the actual upload and that was working great. But there was no clear way to test adding a file to the form. How can I import that helper and how do I provide it a file in the correct format? I'm assuming it should be |
Ahh, ok, you can import by: import File from 'ember-file-upload/file'; |
Thanks I was able to get this working by importing: import File from 'ember-file-upload/file';
import upload from 'app-name/tests/helpers/upload'; And then passing a blob rather than a file to the uploader, e.g.: let file = File.fromDataURL('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=');
upload('input[type=file]', file.blob, 'foo.png'); Just passing a file meant that the |
I'll try to unwrap a file in the test helper so you can pass a file or a blob. |
When I do as @john-griffin mentioned in his comment, I get
Is there a full working example somewhere? It would be really helpful. This is my test code at the moment.
|
Sending through the entire event to the action allows for fake files to
be injected when testing. See these links for more info:
emberjs/ember.js#13540 (comment)
https://medium.com/@chrisdmasters/acceptance-testing-file-uploads-in-ember-2-5-1c9c8dbe5368