Skip to content

Commit 0c1991e

Browse files
authored
Merge pull request #4 from simonihmig/find
Transform to this.element.querySelector(All)
2 parents 219ddd8 + 3932cee commit 0c1991e

45 files changed

Lines changed: 182 additions & 296 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ ember-test-helpers-codemod --type=acceptance tests/acceptance
3232

3333
This addon will perform the following transformations suitable for integration tests:
3434

35-
| Before | After | Transform |
36-
|------------------------------------------------------|-----------------------------------------------------------------------|----------------|
37-
| `this.$('.foo').attr('id')` | `find('.foo').id` | `attr.js` |
38-
| `this.$('.foo').attr('data-test')` | `find('.foo').getAttribute('data-test')` | `attr.js` |
39-
| `this.$('.foo').click()` | `await click('.foo')` | `click.js` |
40-
| `this.$('.foo').change()` (and more events) | `await triggerEvent('.foo', 'change')` | `trigger-shortcut.js` |
41-
| `this.$('.foo').trigger('input')` | `await triggerEvent('.foo', 'input')` | `trigger.js` |
42-
| `this.$('.foo').focus()` | `await focus('.foo')` | `focus.js` |
43-
| `this.$('.foo').val()` | `find('.foo').value` | `get-value.js` |
44-
| `this.$('div').hasClass('foo')` | `find('div').classList.contains('foo')` | `has-class.js` |
45-
| `this.$('.foo').trigger('click')` | `await click('.foo')` | `key-event.js` |
46-
| `this.$('.foo').trigger('keydown', { keyCode: 13 })` | `await keyEvent('.foo', 'keydown', 13)` | `key-event.js` |
47-
| `this.$('.foo').length` | `findAll('.foo').length` | `length.js` |
48-
| `this.$('.foo').prop('tagName')` | `find('.foo').tagName` | `prop.js` |
49-
| `this.$('.foo').val('foo')` | `await fillIn('.foo', 'foo')` | `set-value.js` |
50-
| `this.$('.foo').val('bar').change()` | `await fillIn('.foo', 'foo'); await blur('.foo');` | `set-value.js` |
51-
| `this.$('.foo').val('bar').trigger('input')` | `await fillIn('.foo', 'foo')` | `set-value.js` |
52-
| `this.$('.foo').text()` | `find('.foo').textContent` | `text.js` |
53-
| `this.$('.foo').html()` | `find('.foo').innerHTML` | `html.js` |
54-
| `this.$('.foo').html('foo')` | `find('.foo').innerHTML = 'foo'` | `html.js` |
55-
| `this.$('.foo').each((index, elem) => {...})` | `findAll('.foo').forEach((elem, index) => {...})` | `each.js` |
35+
| Before | After | Transform |
36+
|------------------------------------------------------|---------------------------------------------------------------------------------------------|----------------|
37+
| `this.$('.foo').attr('id')` | `this.element.querySelector('.foo').id` | `attr.js` |
38+
| `this.$('.foo').attr('data-test')` | `this.element.querySelector('.foo').getAttribute('data-test')` | `attr.js` |
39+
| `this.$('.foo').click()` | `await click('.foo')` | `click.js` |
40+
| `this.$('.foo').change()` (and more events) | `await triggerEvent('.foo', 'change')` | `trigger-shortcut.js` |
41+
| `this.$('.foo').trigger('input')` | `await triggerEvent('.foo', 'input')` | `trigger.js` |
42+
| `this.$('.foo').focus()` | `await focus('.foo')` | `focus.js` |
43+
| `this.$('.foo').val()` | `this.element.querySelector('.foo').value` | `get-value.js` |
44+
| `this.$('div').hasClass('foo')` | `this.element.querySelector('div').classList.contains('foo')` | `has-class.js` |
45+
| `this.$('.foo').trigger('click')` | `await click('.foo')` | `key-event.js` |
46+
| `this.$('.foo').trigger('keydown', { keyCode: 13 })` | `await keyEvent('.foo', 'keydown', 13)` | `key-event.js` |
47+
| `this.$('.foo').length` | `this.element.querySelectorAll('.foo').length` | `length.js` |
48+
| `this.$('.foo').prop('tagName')` | `this.element.querySelector('.foo').tagName` | `prop.js` |
49+
| `this.$('.foo').val('foo')` | `await fillIn('.foo', 'foo')` | `set-value.js` |
50+
| `this.$('.foo').val('bar').change()` | `await fillIn('.foo', 'foo'); await blur('.foo');` | `set-value.js` |
51+
| `this.$('.foo').val('bar').trigger('input')` | `await fillIn('.foo', 'foo')` | `set-value.js` |
52+
| `this.$('.foo').text()` | `this.element.querySelector('.foo').textContent` | `text.js` |
53+
| `this.$('.foo').html()` | `this.element.querySelector('.foo').innerHTML` | `html.js` |
54+
| `this.$('.foo').html('foo')` | `this.element.querySelector('.foo').innerHTML = 'foo'` | `html.js` |
55+
| `this.$('.foo').each((index, elem) => {...})` | `this.element.querySelectorAll('.foo').forEach((elem, index) => {...})` | `each.js` |
5656

5757

5858
If you want to run only selected transforms on your code, you can just the needed transform:
@@ -65,24 +65,24 @@ jscodeshift -t ../ember-test-helpers-codemod/lib/transforms/click.js tests/integ
6565

6666
These transformations are available for acceptance tests:
6767

68-
| Before | After | Transform |
69-
|------------------------------------------------------|-----------------------------------------------------------------------|----------------|
70-
| `find('.foo').attr('id')` | `find('.foo').id` | `attr.js` |
71-
| `find('.foo').attr('data-test')` | `find('.foo').getAttribute('data-test')` | `attr.js` |
72-
| `click('.foo')` | `await click('.foo')` | `click.js` |
73-
| `fillIn('#bar', 'baz')` | `await fillIn('#bar', 'baz')` | `fill-in.js` |
74-
| `triggerEvent('input', 'focus')` | `await focus('.foo')` | `trigger-event.js` |
75-
| `triggerEvent('input', 'blur')` | `await blur('.foo')` | `trigger-event.js` |
76-
| `triggerEvent('input', 'mouseenter')` | `await triggerEvent('input', 'mouseenter')` | `trigger-event.js` |
77-
| `find('.foo').val()` | `find('.foo').value` | `get-value.js` |
78-
| `find('div').hasClass('foo')` | `find('div').classList.contains('foo')` | `has-class.js` |
79-
| `keyEvent('#bar', 'keypress', 13);` | `await keyEvent('.foo', 'keydown', 13)` | `key-event.js` |
80-
| `find('.foo').length` | `findAll('.foo').length` | `length.js` |
81-
| `find('.foo').prop('tagName')` | `find('.foo').tagName` | `prop.js` |
82-
| `find('.foo').text()` | `find('.foo').textContent` | `text.js` |
83-
| `find('.foo').html()` | `find('.foo').innerHTML` | `html.js` |
84-
| `find('.foo').html('foo')` | `find('.foo').innerHTML = 'foo'` | `html.js` |
85-
| `find('.foo').each((index, elem) => {...})` | `findAll('.foo').forEach((elem, index) => {...})` | `each.js` |
68+
| Before | After | Transform |
69+
|------------------------------------------------------|---------------------------------------------------------------------------------------------|----------------|
70+
| `find('.foo').attr('id')` | `this.element.querySelector('.foo').id` | `attr.js` |
71+
| `find('.foo').attr('data-test')` | `this.element.querySelector('.foo').getAttribute('data-test')` | `attr.js` |
72+
| `click('.foo')` | `await click('.foo')` | `click.js` |
73+
| `fillIn('#bar', 'baz')` | `await fillIn('#bar', 'baz')` | `fill-in.js` |
74+
| `triggerEvent('input', 'focus')` | `await focus('.foo')` | `trigger-event.js` |
75+
| `triggerEvent('input', 'blur')` | `await blur('.foo')` | `trigger-event.js` |
76+
| `triggerEvent('input', 'mouseenter')` | `await triggerEvent('input', 'mouseenter')` | `trigger-event.js` |
77+
| `find('.foo').val()` | `this.element.querySelector('.foo').value` | `get-value.js` |
78+
| `find('div').hasClass('foo')` | `this.element.querySelector('div').classList.contains('foo')` | `has-class.js` |
79+
| `keyEvent('#bar', 'keypress', 13);` | `await keyEvent('.foo', 'keydown', 13)` | `key-event.js` |
80+
| `find('.foo').length` | `this.element.querySelectorAll('.foo').length` | `length.js` |
81+
| `find('.foo').prop('tagName')` | `this.element.querySelector('.foo').tagName` | `prop.js` |
82+
| `find('.foo').text()` | `this.element.querySelector('.foo').textContent` | `text.js` |
83+
| `find('.foo').html()` | `this.element.querySelector('.foo').innerHTML` | `html.js` |
84+
| `find('.foo').html('foo')` | `this.element.querySelector('.foo').innerHTML = 'foo'` | `html.js` |
85+
| `find('.foo').each((index, elem) => {...})` | `this.element.querySelectorAll('.foo').forEach((elem, index) => {...})` | `each.js` |
8686

8787
If you want to run only selected transforms on your code, you can just the needed transform:
8888

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { find } from '@ember/test-helpers';
21
import { test } from 'qunit';
32
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
43

54
moduleForAcceptance('find');
65

76
test('visiting /foo', function(assert) {
8-
assert.equal(find('.foo').id, 'foo');
9-
assert.equal(find('.foo').getAttribute('data-test'), 'foo');
7+
assert.equal(this.element.querySelector('.foo').id, 'foo');
8+
assert.equal(this.element.querySelector('.foo').getAttribute('data-test'), 'foo');
109
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { click, currentURL, findAll, visit } from '@ember/test-helpers';
1+
import { click, currentURL, visit } from '@ember/test-helpers';
22
import { test } from 'qunit';
33
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
44

@@ -8,6 +8,6 @@ test('visiting /foo', async function(assert) {
88
await visit('/foo');
99

1010
await click('#bar');
11-
await click(findAll('.baz a')[12]);
11+
await click(this.element.querySelectorAll('.baz a')[12]);
1212
assert.equal(currentURL(), '/foo');
1313
});
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
import { findAll } from '@ember/test-helpers';
21
import { test } from 'qunit';
32
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
43

54
moduleForAcceptance('find');
65

76
test('anonymous function callback with two args', function(assert) {
8-
const elemIds = findAll('.button-class').forEach((element, index) => {
7+
const elemIds = this.element.querySelectorAll('.button-class').forEach((element, index) => {
98
assert.equal(element.id, `button${index}`);
109
});
1110
});
1211

1312
test('anonymous function callback with one arg', function(assert) {
14-
const elemIds = findAll('.button-class').forEach((element, index) => {
13+
const elemIds = this.element.querySelectorAll('.button-class').forEach((element, index) => {
1514
assert.equal(element.id, `button${index}`);
1615
});
1716
});
1817

1918
test('function callback with two args', function(assert) {
20-
const elemIds = findAll('.button-class').forEach(function(elem, i) {
19+
const elemIds = this.element.querySelectorAll('.button-class').forEach(function(elem, i) {
2120
assert.equal(element.id, `button${index}`);
2221
});
2322
});
2423

2524
test('function callback with one arg', function(assert) {
26-
const elemIds = findAll('.button-class').forEach((element, index) => {
25+
const elemIds = this.element.querySelectorAll('.button-class').forEach((element, index) => {
2726
assert.equal(element.id, `button${index}`);
2827
});
2928
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fillIn, currentURL, findAll, visit } from '@ember/test-helpers';
1+
import { fillIn, currentURL, visit } from '@ember/test-helpers';
22
import { test } from 'qunit';
33
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
44

@@ -8,6 +8,6 @@ test('visiting /foo', async function(assert) {
88
await visit('/foo');
99

1010
await fillIn('#bar', 'baz');
11-
await fillIn(findAll('#qux input')[5], 'qaaz');
11+
await fillIn(this.element.querySelectorAll('#qux input')[5], 'qaaz');
1212
assert.equal(currentURL(), '/foo');
1313
});
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { find } from '@ember/test-helpers';
21
import { test } from 'qunit';
32
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
43

54
moduleForAcceptance('find');
65

76
test('visiting /foo', function(assert) {
8-
assert.equal(find('.foo').value, 'foo');
7+
assert.equal(this.element.querySelector('.foo').value, 'foo');
98
});
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { find } from '@ember/test-helpers';
21
import { test } from 'qunit';
32
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
43

54
moduleForAcceptance('find');
65

76
test('visiting /foo', function(assert) {
8-
assert.ok(find('.foo').classList.contains('foo'));
7+
assert.ok(this.element.querySelector('.foo').classList.contains('foo'));
98
});
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { find } from '@ember/test-helpers';
21
import { test } from 'qunit';
32
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
43

54
moduleForAcceptance('find');
65

76
test('visiting /foo', function(assert) {
8-
assert.equal(find('.foo').innerHTML.trim(), '');
7+
assert.equal(this.element.querySelector('.foo').innerHTML.trim(), '');
98

10-
find('.foo').innerHTML = 'bar';
9+
this.element.querySelector('.foo').innerHTML = 'bar';
1110

12-
assert.equal(find('.foo').innerHTML.trim(), 'bar');
11+
assert.equal(this.element.querySelector('.foo').innerHTML.trim(), 'bar');
1312
});
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { findAll } from '@ember/test-helpers';
21
import { test } from 'qunit';
32
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
43

54
moduleForAcceptance('find');
65

76
test('visiting /foo', function(assert) {
8-
assert.equal(findAll('.foo').length, 1);
7+
assert.equal(this.element.querySelectorAll('.foo').length, 1);
98
});
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { find } from '@ember/test-helpers';
21
import { test } from 'qunit';
32
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
43

54
moduleForAcceptance('find');
65

76
test('visiting /foo', function(assert) {
8-
assert.equal(find('.foo').tagName, 'DIV');
7+
assert.equal(this.element.querySelector('.foo').tagName, 'DIV');
98
});

0 commit comments

Comments
 (0)