How to use ember-test-helpers - 10 common examples

To help you get started, we’ve selected a few ember-test-helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ciena-frost / ember-frost-core / addon-test-support / frost-select.js View on Github external
export function open (hook = 'select') {
  // In a real browser when you click on the select with your mouse a
  // focusin event is fired on the component. However when using jQuery's
  // click() method the focusin is not fired so we are programitcally
  // triggering that in this test.
  $hook(hook).click().trigger('focusin')
  return wait()
}
github html-next / vertical-collection / tests / helpers / array.js View on Github external
destItemIdx = items.indexOf(destItem) + 1;
      items.insertAt(destItemIdx, sourceItem);
    } else {
      // native array
      destItem = items[destItemIdx];
      sourceItem = items[sourceItemIdx];
      items.splice(sourceItemIdx, 1);
      destItemIdx = items.indexOf(destItem) + 1;
      items.splice(destItemIdx, 0, sourceItem);
      // if we are not using Ember Arrays we need to set `items` to a new array
      // instance to trigger a recompute on `virtualComponents`
      context.set('items', [].concat(items));
    }
  });

  return wait();
}
github Addepar / ember-table / tests / helpers / wait-for-render.js View on Github external
export default function() {
  return wait().then(() => {
    return new EmberPromise((resolve) => {
      // Two RAFs needed since we take 3 frames to do the initial render
      requestAnimationFrame(() => requestAnimationFrame((resolve)));
    });
  });
}
github DefinitelyTyped / DefinitelyTyped / types / ember-test-helpers / ember-test-helpers-tests.ts View on Github external
QUnit.module(module.name, {
        beforeEach() {
            module.setup();
        },
        afterEach() {
            module.teardown();
        }
    });
}

async function testWait() {
    await wait();
}

if (hasEmberVersion(2, 10)) {
    // ...
}

// https://github.com/emberjs/ember-test-helpers/blob/f07e86914f2a3823c4cb6787307f9ba2bf447e68/tests/unit/setup-context-test.js
QUnit.test('it sets up this.owner', function(this: TestContext, assert: Assert) {
    const { owner } = this;
    assert.ok(owner, 'owner was setup');
    assert.equal(typeof owner.lookup, 'function', 'has expected lookup interface');

    if (hasEmberVersion(2, 12)) {
      assert.equal(typeof owner.factoryFor, 'function', 'has expected factory interface');
    }
});

QUnit.test('can pauseTest to be resumed "later"', async function(this: TestContext, assert: Assert) {
    const promise = this.pauseTest();
github emberjs / ember-qunit / lib / ember-qunit / test-wrapper.js View on Github external
function wrapper() {
    var context = getContext();

    var result = callback.apply(context, arguments);

    function failTestOnPromiseRejection(reason) {
      var message;
      if (reason instanceof Error) {
        message = reason.stack;
        if (reason.message && message && message.indexOf(reason.message) < 0) {
          // PhantomJS has a `stack` that does not contain the actual
          // exception message.
          message = Ember.inspect(reason) + "\n" + message;
        }
      } else {
        message = Ember.inspect(reason);
      }
      ok(false, message);
github adopted-ember-addons / ember-collection / tests / helpers / module-for-view.js View on Github external
import { deprecate } from '@ember/application/deprecations';
import { tryInvoke } from '@ember/utils';
import { run } from '@ember/runloop';
import { merge } from '@ember/polyfills';
import Ember from 'ember';
import TestModule from 'ember-test-helpers/test-module';
import { getResolver } from 'ember-test-helpers/test-resolver';
import { createModule } from 'ember-qunit/qunit-module';

var TestModuleForView = TestModule.extend({
  init: function(viewName, description, callbacks) {
    this.viewName = viewName;
    this._super.call(this, 'component:' + viewName, description, callbacks);
    this.setupSteps.push(this.setupView);
  },
  initNeeds: function() {
    this.needs = [];
    // toplevel refers to class extended from Ember.View
    if (this.subjectName !== 'component:toplevel') {
      this.needs.push(this.subjectName);
    }
    if (this.callbacks.needs) {
      this.needs = this.needs.concat(this.callbacks.needs);
      delete this.callbacks.needs;
    }
  },
github cibernox / ember-native-dom-helpers / addon-test-support / flush-scroll-and-wait.js View on Github external
export function flushScrollAndWait() {
  return wait().then(() => {
    return new Ember.RSVP.Promise((resolve) => {
      window.requestAnimationFrame(resolve);
    });
  });
}
github ember-cli / ember-twiddle / tests / helpers / wait-for-unloaded-iframe.js View on Github external
export default function(app) {
  let ctx = { app };
  Test.registerWaiter(ctx, hasNoIframe);

  return wait().then(() => {
    Test.unregisterWaiter(ctx, hasNoIframe);
    return RSVP.resolve();
  }).then(() => {
    return new RSVP.Promise(function (resolve) {
      run.later(resolve, 10);
    });
  });
}
github html-next / vertical-collection / tests / helpers / array.js View on Github external
export function replaceArray(context, items) {
  const oldItems = context.get('items');

  run(() => {
    if (EmberArray.detect(oldItems)) {
      context.set('items', A(items));
    } else {
      context.set('items', items);
    }
  });

  return wait();
}