UNPKG

ember-native-dom-helpers

Version:

Test helpers for your integration tests that fire native events

33 lines (27 loc) 1.02 kB
import { run } from '@ember/runloop'; import { assert } from '@ember/debug'; import { isArray } from '@ember/array'; import getElementWithAssert from './-private/get-element-with-assert'; import { fireEvent } from './fire-event'; import { wait } from './-private/compatibility'; /* @method selectFiles @param {String|HTMLElement} selector @param {Array} files @return {RSVP.Promise} @public */ export function selectFiles(selector, files = []) { let element = getElementWithAssert(selector); assert(`This is only used with file inputs. Either change to a 'type="file"' or use the 'triggerEvent' helper.`, element.type === 'file'); if (!isArray(files)) { files = [files]; } assert(`Can only handle multiple selection when an input is set to allow for multiple files. Please add the property "multiple" to your file input.`, element.multiple || files.length <= 1); run(() => fireEvent(element, 'change', files)); return (window.wait || wait)(); }