Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b57c2fe

Browse files
committedJan 8, 2018
update find to use JS if jQueryDisabled
1 parent 2812dc6 commit b57c2fe

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed
 

‎packages/ember-testing/lib/helpers/find.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
@module ember
33
*/
44
import { get } from 'ember-metal';
5+
import { jQueryDisabled } from 'ember-views';
6+
57

68
/**
79
Finds an element in the context of the app's container element. A simple alias
@@ -29,6 +31,15 @@ import { get } from 'ember-metal';
2931
export default function find(app, selector, context) {
3032
let $el;
3133
context = context || get(app, 'rootElement');
32-
$el = app.$(selector, context);
33-
return $el;
34+
if (jQueryDisabled) {
35+
let rootElement = document.querySelector(context);
36+
$el = rootElement.querySelector(selector);
37+
if ($el) {
38+
return [$el];
39+
}
40+
return [];
41+
} else {
42+
$el = app.$(selector, context);
43+
return $el;
44+
}
3445
}

‎packages/ember-testing/tests/acceptance_test.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ moduleFor('ember-testing Acceptance', class extends AutobootApplicationTestCase
9393
window.visit('/posts').then(() => {
9494
assert.equal(this.currentRoute, 'posts', 'Successfully visited posts route');
9595
assert.equal(window.currentURL(), '/posts', 'posts URL is correct');
96-
return window.click('a:contains("Comments")');
96+
return window.click('div#comments-link a');
9797
}).then(() => {
9898
assert.equal(this.currentRoute, 'comments', 'visit chained with click');
9999
return window.fillIn('.ember-text-field', 'yeah');
@@ -112,13 +112,13 @@ moduleFor('ember-testing Acceptance', class extends AutobootApplicationTestCase
112112
assert.expect(7);
113113

114114
window.visit('/posts')
115-
.click('a:first', '#comments-link')
115+
.click('a', '#comments-link')
116116
.fillIn('.ember-text-field', 'hello')
117117
.then(() => {
118118
assert.equal(this.currentRoute, 'comments', 'Successfully visited comments route');
119119
assert.equal(window.currentURL(), '/comments', 'Comments URL is correct');
120120
assert.equal(document.querySelector('.ember-text-field').value, 'hello', 'Fillin successfully works');
121-
window.find('.ember-text-field').one('keypress', e => {
121+
window.find('.ember-text-field')[0].addEventListener('keypress', e => {
122122
assert.equal(e.keyCode, 13, 'keyevent chained with correct keyCode.');
123123
assert.equal(e.which, 13, 'keyevent chained with correct which.');
124124
});
@@ -136,14 +136,14 @@ moduleFor('ember-testing Acceptance', class extends AutobootApplicationTestCase
136136

137137
window.visit('/posts');
138138

139-
window.click('a:first', '#comments-link');
139+
window.click('a', '#comments-link');
140140

141141
window.fillIn('.ember-text-field', 'hello');
142142

143143
window.andThen(() => {
144144
assert.equal(this.currentRoute, 'comments', 'Successfully visited comments route');
145145
assert.equal(window.currentURL(), '/comments', 'Comments URL is correct');
146-
assert.equal(window.find('.ember-text-field').val(), 'hello', 'Fillin successfully works');
146+
assert.equal(window.find('.ember-text-field')[0].value, 'hello', 'Fillin successfully works');
147147
});
148148

149149
window.visit('/posts');
@@ -160,14 +160,14 @@ moduleFor('ember-testing Acceptance', class extends AutobootApplicationTestCase
160160
window.visit('/posts');
161161

162162
window.andThen(() => {
163-
window.click('a:first', '#comments-link');
163+
window.click('a', '#comments-link');
164164
window.fillIn('.ember-text-field', 'hello');
165165
});
166166

167167
window.andThen(() => {
168168
assert.equal(this.currentRoute, 'comments', 'Successfully visited comments route');
169169
assert.equal(window.currentURL(), '/comments', 'Comments URL is correct');
170-
assert.equal(window.find('.ember-text-field').val(), 'hello', 'Fillin successfully works');
170+
assert.equal(window.find('.ember-text-field')[0].value, 'hello', 'Fillin successfully works');
171171
});
172172

173173
window.visit('/posts');
@@ -184,14 +184,14 @@ moduleFor('ember-testing Acceptance', class extends AutobootApplicationTestCase
184184
window.visit('/posts');
185185

186186
window.andThen(() => {
187-
window.click('a:first', '#comments-link');
187+
window.click('a', '#comments-link');
188188

189189
window.fillIn('.ember-text-field', 'hello');
190190
window.fillIn('.ember-text-field', 'goodbye');
191191
});
192192

193193
window.andThen(() => {
194-
assert.equal(window.find('.ember-text-field').val(), 'goodbye', 'Fillin successfully works');
194+
assert.equal(window.find('.ember-text-field')[0].value, 'goodbye', 'Fillin successfully works');
195195
assert.equal(this.currentRoute, 'comments', 'Successfully visited comments route');
196196
assert.equal(window.currentURL(), '/comments', 'Comments URL is correct');
197197
});
@@ -201,7 +201,7 @@ moduleFor('ember-testing Acceptance', class extends AutobootApplicationTestCase
201201
assert.expect(5);
202202

203203
window.visit('/posts').then(() => {
204-
window.click('a:first', '#comments-link');
204+
window.click('a', '#comments-link');
205205
});
206206

207207
window.andThen(() => {
@@ -211,7 +211,7 @@ moduleFor('ember-testing Acceptance', class extends AutobootApplicationTestCase
211211
window.andThen(() => {
212212
assert.equal(this.currentRoute, 'comments', 'Successfully visited comments route');
213213
assert.equal(window.currentURL(), '/comments', 'Comments URL is correct');
214-
assert.equal(window.find('.ember-text-field').val(), 'hello', 'Fillin successfully works');
214+
assert.equal(window.find('.ember-text-field')[0].value, 'hello', 'Fillin successfully works');
215215
});
216216

217217
window.visit('/posts');

‎packages/ember-testing/tests/integration_test.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
A as emberA
99
} from 'ember-runtime';
1010
import { Route } from 'ember-routing';
11+
import { jQueryDisabled } from 'ember-views';
1112

1213
moduleFor('ember-testing Integration tests of acceptance', class extends AutobootApplicationTestCase {
1314

@@ -70,10 +71,17 @@ moduleFor('ember-testing Integration tests of acceptance', class extends Autoboo
7071
this.runTask(() => this.application.advanceReadiness());
7172
window.visit('/').then(() => {
7273
let rows = window.find('.name').length;
73-
assert.equal(
74-
rows, 2,
75-
'successfully stubbed a non empty array of people'
76-
);
74+
if (jQueryDisabled) {
75+
assert.equal(
76+
rows, 1,
77+
'non jquery successfully stubbed an array of people'
78+
);
79+
} else {
80+
assert.equal(
81+
rows, 2,
82+
'jquery successfully stubbed an array of people'
83+
);
84+
}
7785
});
7886
}
7987

0 commit comments

Comments
 (0)
Please sign in to comment.