[File Api]: How to Test <input type="file"> ?

Hi,

my name is Fabian Raetz.
I'm searching a way to unit test file uploads but i can't find any
solutions to that problem on the web.

The only way to test file uploads via javascript testing frameworks like
Jasmine <http://pivotal.github.io/jasmine/> i've found is via PhantomJS's
uploadFile method<https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#wiki-webpage-uploadFile>.
It would be awesome if you know a solution that works in Firefox / Chrome

Here some pseudo code (not working) that would fit my need:

it("should trigger change event", function() {
  var result,
       expected = new File(....),  // no File Constructor available...
maybe with base64 encoded image as input
       element = jqLite('<input type="file">');

element.bind('change', function(e) {
  result = e.target.files;
});

element.val(expected); // not working....

expect(result.length).toBe(1);
expect(result[0]).toEqual(expected);
});

Any suggestions?

Thanks and Best Regards,

Fabian Raetz

Received on Thursday, 30 May 2013 20:55:49 UTC