Skip to content

prakashchokalingam/fill-in-file

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
lib
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

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