Skip to content

prakashchokalingam/fill-in-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fill-in-file npm version

A test util that helps to fill files in your file input element

Usage

fillInFile('#input-element', { url: 'base64content', name: 'example.jpg' })

Install

npm install fill-in-file

How

Please check this article for implementation details.

Variants

Simple mock
fillInFile('#input-element')

It automatically adds the mock js-base64 image and triggers the onchange event.

String
fillInFile('#input-element', 'base64content')

 or

fillInFile('#input-element', 'https://some-public-file-url.jpg');
Single file object
fillInFile('#input-element', { url: 'base64content', name: 'logo.jpg' });

 or

fillInFile('#input-element', { url: 'https://some-public-file-url.jpg', name:  'profile.jpg' });

It adds the given file to the file input and triggers the onchange event.

Multiple files
let files = [
  { url: 'base64content', name: 'logo.jpg' },
  { url: 'https://some-public-file-url.jpg', name:  'profile.jpg' }
];

fillInFile('#input-element', files);

API

Method: fillInFile

params:

name type required description
domSelector string yes dom query selector string for the input file element
files undefined - string - file - [file] optional file contents to be added to the file element
options object optional supports options like documentContext that lets you pass a custom document context, by default util uses global document

ember test helper

https://github.com/prakashchokalingam/ember-fill-in-file

Examples

Qunit: https://prakashchokalingam.github.io/fill-in-file/examples/qunit.html

Mocha: https://prakashchokalingam.github.io/fill-in-file/examples/mocha.html

npm version npm