Skip to content

Commit c88dbf1

Browse files
authored
Add missing deprecation message for this.$() (#153)
Add missing deprecation message for `this.$()`
2 parents 52886ad + dd96dd5 commit c88dbf1

File tree

3 files changed

+19
-41
lines changed

3 files changed

+19
-41
lines changed

tests/integration/components/component-dot-dollar-test.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,17 @@ module('Integration | Component | component-dot-dollar', function(hooks) {
1919
this.setJQueryElement = ($) => this.$element = $;
2020
});
2121

22-
test('it implements Component.$()', function(assert) {
23-
return assert.noDeprecations(async () => {
24-
await render(hbs`{{jquery-component id="jq" setJQueryElement=setJQueryElement}}`);
22+
test('it implements Component.$()', async function(assert) {
23+
await render(hbs`{{jquery-component id="jq" setJQueryElement=setJQueryElement}}`);
2524

26-
assert.ok(this.$element, 'Component.$() is available');
27-
assert.ok(this.$element instanceof jQuery, 'Component.$() returns a jQuery object');
28-
assert.equal(this.$element.get(0), this.element.querySelector('#jq'), 'Component.$() is a jQuery wrapper around Component.element');
29-
});
25+
assert.ok(this.$element, 'Component.$() is available');
26+
assert.ok(this.$element instanceof jQuery, 'Component.$() returns a jQuery object');
27+
assert.equal(this.$element.get(0), this.element.querySelector('#jq'), 'Component.$() is a jQuery wrapper around Component.element');
3028
});
3129

32-
test('it implements Component.$(selector)', function(assert) {
33-
return assert.noDeprecations(async () => {
34-
await render(hbs`{{#jquery-component id="jq" selector="div" setJQueryElement=setJQueryElement}}<div id="child"/>{{/jquery-component}}`);
30+
test('it implements Component.$(selector)', async function(assert) {
31+
await render(hbs`{{#jquery-component id="jq" selector="div" setJQueryElement=setJQueryElement}}<div id="child"/>{{/jquery-component}}`);
3532

36-
assert.equal(this.$element.get(0), this.element.querySelector('#child'), 'Component.$(selector) is a jQuery object of the child elements matching selector');
37-
});
33+
assert.equal(this.$element.get(0), this.element.querySelector('#child'), 'Component.$(selector) is a jQuery object of the child elements matching selector');
3834
});
3935
});

tests/test-helper.js

-28
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,8 @@
1-
import QUnit from 'qunit';
2-
import { registerDeprecationHandler } from '@ember/debug';
31
import Application from '../app';
42
import config from '../config/environment';
53
import { setApplication } from '@ember/test-helpers';
64
import { start } from 'ember-qunit';
75

8-
let deprecations;
9-
10-
registerDeprecationHandler((message, options, next) => {
11-
// in case a deprecation is issued before a test is started
12-
if (!deprecations) {
13-
deprecations = [];
14-
}
15-
16-
deprecations.push(message);
17-
next(message, options);
18-
});
19-
20-
QUnit.testStart(function() {
21-
deprecations = [];
22-
});
23-
24-
QUnit.assert.noDeprecations = async function(callback) {
25-
let originalDeprecations = deprecations;
26-
deprecations = [];
27-
28-
await callback();
29-
this.deepEqual(deprecations, [], 'Expected no deprecations during test.');
30-
31-
deprecations = originalDeprecations;
32-
};
33-
346
setApplication(Application.create(config.APP));
357

368
start();

vendor/jquery/component.dollar.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert } from '@ember/debug';
1+
import { assert, deprecate } from '@ember/debug';
22

33
(function() {
44
Ember.Component.reopen({
@@ -8,6 +8,16 @@ import { assert } from '@ember/debug';
88
this.tagName !== ''
99
);
1010

11+
deprecate(
12+
'Using this.$() in a component has been deprecated, consider using this.element',
13+
false,
14+
{
15+
id: 'ember-views.curly-components.jquery-element',
16+
until: '4.0.0',
17+
url: 'https://emberjs.com/deprecations/v3.x#toc_jquery-apis',
18+
}
19+
);
20+
1121
if (this.element) {
1222
return sel ? jQuery(sel, this.element) : jQuery(this.element);
1323
}

0 commit comments

Comments
 (0)