Skip to content

Latest commit

 

History

History

acceptance

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

acceptance

Usage

npx ember-test-helpers-codemod acceptance path/of/files/ or/some**/*glob.js

# or

yarn global add ember-test-helpers-codemod
ember-test-helpers-codemod acceptance path/of/files/ or/some**/*glob.js

Input / Output


andthen

Input (andthen.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('click');

test('visiting /foo', function(assert) {
  visit('/foo');
  andThen(function() {
  });

  andThen(function() {
    assert.ok(true);
  });
});

test('visiting /foo', function(assert) {
  visit('/foo');
  return andThen(function() {
  });
});

test('visiting /foo', function(assert) {
  visit('/foo');
  return andThen(function() {
    assert.ok(true);
  });
});

Output (andthen.input.js):

import { visit } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('click');

test('visiting /foo', async function(assert) {
  await visit('/foo');
  assert.ok(true);
});

test('visiting /foo', async function(assert) {
  await visit('/foo');
});

test('visiting /foo', async function(assert) {
  await visit('/foo');
  assert.ok(true);
});

attr

Input (attr.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(find('.foo').attr('id'), 'foo');
  assert.equal(find('.foo').attr('data-test'), 'foo');
});

Output (attr.input.js):

import { find } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(find('.foo').id, 'foo');
  assert.equal(find('.foo').getAttribute('data-test'), 'foo');
});

click

Input (click.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('click');

test('visiting /foo', function(assert) {
  visit('/foo');

  click('#bar');
  click('.baz a:eq(12)');
  andThen(function() {
    assert.equal(currentURL(), '/foo');
  });
});

Output (click.input.js):

import { click, currentURL, findAll, visit } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('click');

test('visiting /foo', async function(assert) {
  await visit('/foo');

  await click('#bar');
  await click(findAll('.baz a')[12]);
  assert.equal(currentURL(), '/foo');
});

each

Input (each.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('anonymous function callback with two args', function(assert) {
  const elemIds = find('.button-class').each((index, element) => {
    assert.equal(element.id, `button${index}`);
  });
});

test('anonymous function callback with one arg', function(assert) {
  const elemIds = find('.button-class').each((index) => {
    assert.equal(element.id, `button${index}`);
  });
});

test('function callback with two args', function(assert) {
  const elemIds = find('.button-class').each(function(i, elem) {
    assert.equal(element.id, `button${index}`);
  });
});

test('function callback with one arg', function(assert) {
  const elemIds = find('.button-class').each((index) => {
    assert.equal(element.id, `button${index}`);
  });
});

Output (each.input.js):

import { findAll } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('anonymous function callback with two args', function(assert) {
  const elemIds = findAll('.button-class').forEach((element, index) => {
    assert.equal(element.id, `button${index}`);
  });
});

test('anonymous function callback with one arg', function(assert) {
  const elemIds = findAll('.button-class').forEach((element, index) => {
    assert.equal(element.id, `button${index}`);
  });
});

test('function callback with two args', function(assert) {
  const elemIds = findAll('.button-class').forEach(function(elem, i) {
    assert.equal(element.id, `button${index}`);
  });
});

test('function callback with one arg', function(assert) {
  const elemIds = findAll('.button-class').forEach((element, index) => {
    assert.equal(element.id, `button${index}`);
  });
});

fill-in

Input (fill-in.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('fillIn');

test('visiting /foo', function(assert) {
  visit('/foo');

  fillIn('#bar', 'baz');
  fillIn('#qux input:eq(5)', 'qaaz');
  andThen(function() {
    assert.equal(currentURL(), '/foo');
  });
});

Output (fill-in.input.js):

import { fillIn, currentURL, findAll, visit } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('fillIn');

test('visiting /foo', async function(assert) {
  await visit('/foo');

  await fillIn('#bar', 'baz');
  await fillIn(findAll('#qux input')[5], 'qaaz');
  assert.equal(currentURL(), '/foo');
});

get-value

Input (get-value.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(find('.foo').val(), 'foo');
});

Output (get-value.input.js):

import { find } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(find('.foo').value, 'foo');
});

get

Input (get.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('get');

test('transforms get() correctly', function(assert) {
  assert.ok(find('.foo bar').get(3));

  const otherGet = someOtherObj.get(1);
});

Output (get.input.js):

import { findAll } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('get');

test('transforms get() correctly', function(assert) {
  assert.ok(findAll('.foo bar')[3]);

  const otherGet = someOtherObj.get(1);
});

has-class

Input (has-class.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.ok(find('.foo').hasClass('foo'));
});

Output (has-class.input.js):

import { find } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.ok(find('.foo').classList.contains('foo'));
});

html

Input (html.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(find('.foo').html().trim(), '');

  find('.foo').html('bar');

  assert.equal(find('.foo').html().trim(), 'bar');
});

Output (html.input.js):

import { find } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(find('.foo').innerHTML.trim(), '');

  find('.foo').innerHTML = 'bar';

  assert.equal(find('.foo').innerHTML.trim(), 'bar');
});

key-event

Input (key-event.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('keyEvent');

test('visiting /foo', function(assert) {
  visit('/foo');

  keyEvent('#bar', 'keypress', 13);
  andThen(function() {
    assert.equal(currentURL(), '/foo');
  });
});

Output (key-event.input.js):

import { keyEvent, currentURL, visit } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('keyEvent');

test('visiting /foo', async function(assert) {
  await visit('/foo');

  await keyEvent('#bar', 'keypress', 13);
  assert.equal(currentURL(), '/foo');
});

length

Input (length.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(find('.foo').length, 1);
});

Output (length.input.js):

import { findAll } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(findAll('.foo').length, 1);
});

nested-in-and-then

Input (nested-in-and-then.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /twiddles', function(assert) {
  andThen(function() {
    click('.foo');
  });

  andThen(() => {
    click('.foo');
  });

  andThen(function() {
    andThen(function() {
      andThen(function() {
        click('.foo');
      });
    });
  });

  andThen(() => {
    assert.ok(true);
  });

  andThen(() => assert.ok(true));
});

test('visiting /twiddles', function(assert) {
  andThen(() => {
    click('.foo');
  });
});

Output (nested-in-and-then.input.js):

import { click } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /twiddles', async function(assert) {
  await click('.foo');

  await click('.foo');

  await click('.foo');

  assert.ok(true);

  assert.ok(true);
});

test('visiting /twiddles', async function(assert) {
  await click('.foo');
});

prop

Input (prop.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(find('.foo').prop('tagName'), 'DIV');
});

Output (prop.input.js):

import { find } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(find('.foo').tagName, 'DIV');
});

route-helpers

Input (route-helpers.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('click');

test('visiting /foo', function(assert) {
  visit('/foo');
  assert.equal(currentURL(), '/foo');
  assert.equal(currentPath(), 'foo.index');
  assert.equal(currentRouteName(), 'foo');
});

Output (route-helpers.input.js):

import { currentURL, currentPath, currentRouteName, visit } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('click');

test('visiting /foo', async function(assert) {
  await visit('/foo');
  assert.equal(currentURL(), '/foo');
  assert.equal(currentPath(), 'foo.index');
  assert.equal(currentRouteName(), 'foo');
});

selected

Input (selected.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('selected');

test(':selected is replaced correctly', function(assert) {
  // find
  const checkedVal = find('.foo input:selected').val();
  assert.equal(checkedVal, 13);

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

Output (selected.input.js):

import { find, findAll } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('selected');

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);
});

text

Input (text.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(find('.foo').text().trim(), '');
});

Output (text.input.js):

import { find } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('find');

test('visiting /foo', function(assert) {
  assert.equal(find('.foo').textContent.trim(), '');
});

trigger-event

Input (trigger-event.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('triggerEvent');

test('visiting /foo', function(assert) {
  visit('/foo');

  triggerEvent('input', 'focus');
  triggerEvent('input', 'blur');
  triggerEvent('#bar', 'mouseenter');
  andThen(function() {
    assert.equal(currentURL(), '/foo');
  });
});

Output (trigger-event.input.js):

import { currentURL, blur, focus, triggerEvent, visit } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('triggerEvent');

test('visiting /foo', async function(assert) {
  await visit('/foo');

  await focus('input');
  await blur('input');
  await triggerEvent('#bar', 'mouseenter');
  assert.equal(currentURL(), '/foo');
});

visit

Input (visit.input.js):

import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('click');

test('visiting /foo', function(assert) {
  visit('/foo');
  andThen(function() {
    assert.equal(currentURL(), '/foo');
  });
});

test('visiting /bar', function(assert) {
  visit('/bar');
  andThen(() => {
    assert.equal(currentURL(), '/bar');
  });
});

test('visiting /bar', async function(assert) {
  await visit('/bar');
  assert.equal(currentURL(), '/bar');
});

test('visiting /bar', async function(assert) {
  await assert.rejects(visit('/bar'));
  assert.equal(currentURL(), '/bar');
});

Output (visit.input.js):

import { currentURL, visit } from '@ember/test-helpers';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('click');

test('visiting /foo', async function(assert) {
  await visit('/foo');
  assert.equal(currentURL(), '/foo');
});

test('visiting /bar', async function(assert) {
  await visit('/bar');
  assert.equal(currentURL(), '/bar');
});

test('visiting /bar', async function(assert) {
  await visit('/bar');
  assert.equal(currentURL(), '/bar');
});

test('visiting /bar', async function(assert) {
  await assert.rejects(visit('/bar'));
  assert.equal(currentURL(), '/bar');
});