UNPKG

ember-native-dom-helpers

Version:

Test helpers for your integration tests that fire native events

41 lines (36 loc) 1.18 kB
import { run } from '@ember/runloop'; import getElementWithAssert from './-private/get-element-with-assert'; import isFormControl from './-private/is-form-control'; import { focus } from './focus'; import { fireEvent } from './fire-event'; import { wait } from './-private/compatibility'; import { deprecate } from '@ember/debug'; /* @method fillIn @param {String|HTMLElement} selector @param {String} text @return {RSVP.Promise} @public */ export function fillIn(selector, text) { deprecate( 'Importing `fillIn` from "ember-native-dom-helpers" is deprecated. Since `ember-cli-qunit` 4.3 and `ember-cli-mocha` 0.15.0 you can use `import { fillIn } from "@ember/test-helpers";`', false, { until: '0.7', id: 'ember-native-dom-helpers-fill-in' } ); let el = getElementWithAssert(selector); if (!isFormControl(el) && !el.isContentEditable) { throw new Error('Unable to fill element'); } run(() => focus(el)); run(() => { if (el.isContentEditable) { el.innerHTML = text; } else { el.value = text; } }); run(() => fireEvent(el, 'input')); run(() => fireEvent(el, 'change')); return (window.wait || wait)(); }