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 ember-codemods / ember-test-helpers-codemod / transforms / integration / __testfixtures__ / selected.output.js View on Github external
test(':selected is replaced correctly', function(assert) {
  // find
  const checkedVal = find('.foo input:checked').value;
  assert.equal(checkedVal, 13);

  // findAll
  const checkedCount = findAll('select option:checked').length;
  assert.equal(checkedCount, 3);

  // Multiple jQuery selectors
  const firstChecked = find('.foo input:checked').value;
  const secondChecked = find(findAll('.foo input:checked')[2]).value;
});
github ember-codemods / ember-test-helpers-codemod / transforms / acceptance / __testfixtures__ / selected.output.js View on Github external
test(':selected is replaced correctly', function(assert) {
  // find
  const checkedVal = find('.foo input:checked').value;
  assert.equal(checkedVal, 13);

  // findAll
  const checkedCount = findAll('select option:checked').length;
  assert.equal(checkedCount, 3);
});
github CenterForOpenScience / ember-osf-web / tests / helpers / index.ts View on Github external
export async function visit(url: string) {
    try {
        await _visit(url);
    } catch (e) {
        if (e.message !== 'TransitionAborted') {
            throw e;
        }

        // Set this.element for application tests as the original
        // visit's attempt to do so was interupted by an exception
        const context: any = getContext();
        context.element = document.querySelector('#ember-testing');
    }

    await settled();
}
github CenterForOpenScience / ember-osf-web / tests / helpers / index.ts View on Github external
export async function visit(url: string) {
    try {
        await _visit(url);
    } catch (e) {
        if (e.message !== 'TransitionAborted') {
            throw e;
        }

        // Set this.element for application tests as the original
        // visit's attempt to do so was interupted by an exception
        const context: any = getContext();
        context.element = document.querySelector('#ember-testing');
    }

    await settled();
}
github emberjs / ember-test-helpers / tests / test-helper.js View on Github external
}

  // this is used to ensure that the testing container is always reset properly
  let testElementContainer = document.getElementById('ember-testing-container');
  let actual = testElementContainer.innerHTML;
  let expected = `<div id="ember-testing"></div>`;
  if (actual !== expected) {
    let message = `Expected #ember-testing-container to be reset after ${module}: ${name}, but was \`${actual}\``;
    cleanupFailures.push(message);

    // eslint-disable-next-line
    console.error(message);
    testElementContainer.innerHTML = expected;
  }

  if (!isSettled()) {
    let message = `Expected to be settled after ${module}: ${name}, but was \`${JSON.stringify(
      getSettledState()
    )}\``;
    asyncLeakageFailures.push(message);

    // eslint-disable-next-line
    console.error(message);
  }
});
github cibernox / ember-power-select / addon-test-support / index.js View on Github external
async function openIfClosedAndGetContentId(trigger) {
  let contentId = trigger.attributes['aria-owns'] && `${trigger.attributes['aria-owns'].value}`;
  let content = contentId ? document.querySelector(`#${contentId}`) : undefined;
  // If the dropdown is closed, open it
  if (!content || content.classList.contains('ember-basic-dropdown-content-placeholder')) {
    await click(trigger);
    await settled();
    contentId = `${trigger.attributes['aria-owns'].value}`;
  }
  return contentId;
}
github cibernox / ember-power-select / addon-test-support / index.js View on Github external
trigger.scrollIntoView();
  }

  let isMultipleSelect = !!trigger.querySelector('.ember-power-select-trigger-multiple-input');

  let contentId = await openIfClosedAndGetContentId(trigger);
  let isDefaultSingleSelect = !!document.querySelector('.ember-power-select-search-input');

  if (isMultipleSelect) {
    await fillIn(trigger.querySelector('.ember-power-select-trigger-multiple-input'), value);
  } else if (isDefaultSingleSelect) {
    await fillIn('.ember-power-select-search-input', value);
  } else { // It's probably a customized version
    let inputIsInTrigger = !!trigger.querySelector('.ember-power-select-trigger input[type=search]');
    if (inputIsInTrigger) {
      await fillIn(trigger.querySelector('input[type=search]'), value);
    } else {
      await fillIn(`#${contentId} .ember-power-select-search-input[type=search]`, 'input');
    }
  }
  return settled();
}
github miragejs / ember-cli-mirage / addon / get-rfc232-test-context.js View on Github external
export default function getRfc232TestContext() {
  // Support older versions of `ember-qunit` that don't have
  // `@ember/test-helpers` (and therefore cannot possibly be running an
  // rfc232/rfc268 test).
  if (require.has('@ember/test-helpers')) {
    let { getContext } = require('@ember/test-helpers');
    return getContext();
  }
}
github cibernox / ember-power-select / addon-test-support / index.js View on Github external
async function openIfClosedAndGetContentId(trigger) {
  let contentId = trigger.attributes['aria-owns'] && `${trigger.attributes['aria-owns'].value}`;
  let content = contentId ? document.querySelector(`#${contentId}`) : undefined;
  // If the dropdown is closed, open it
  if (!content || content.classList.contains('ember-basic-dropdown-content-placeholder')) {
    await click(trigger);
    await settled();
    contentId = `${trigger.attributes['aria-owns'].value}`;
  }
  return contentId;
}
github emberjs / ember-test-helpers / tests / helpers / resolver.js View on Github external
import { dasherize } from '@ember/string';
import { assign } from '@ember/polyfills';
import { setRegistry } from '../../resolver';
import { setResolver, setApplication } from '@ember/test-helpers';
import require from 'require';
import App from '../../app';
import config from '../../config/environment';

const AppConfig = assign({ autoboot: false }, config.APP);
export const application = App.create(AppConfig);
export const resolver = application.Resolver.create({
  namespace: application,
  isResolverFromTestHelpers: true,
});

setResolver(resolver);
setApplication(application);

export function setResolverRegistry(registry) {
  setRegistry(registry);
}

export default {
  create() {
    return resolver;
  },
};

export function createCustomResolver(registry) {
  if (require.has('ember-native-dom-event-dispatcher')) {
    // the raw value looked up by ember and these test helpers
    registry['event_dispatcher:main'] = require('ember-native-dom-event-dispatcher').default;