Skip to content

Commit

Permalink
Add missing deprecation message for this.$() (#153)
Browse files Browse the repository at this point in the history
Add missing deprecation message for `this.$()`
  • Loading branch information
rwjblue authored Oct 4, 2019
2 parents 52886ad + dd96dd5 commit c88dbf1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
20 changes: 8 additions & 12 deletions tests/integration/components/component-dot-dollar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,17 @@ module('Integration | Component | component-dot-dollar', function(hooks) {
this.setJQueryElement = ($) => this.$element = $;
});

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

assert.ok(this.$element, 'Component.$() is available');
assert.ok(this.$element instanceof jQuery, 'Component.$() returns a jQuery object');
assert.equal(this.$element.get(0), this.element.querySelector('#jq'), 'Component.$() is a jQuery wrapper around Component.element');
});
assert.ok(this.$element, 'Component.$() is available');
assert.ok(this.$element instanceof jQuery, 'Component.$() returns a jQuery object');
assert.equal(this.$element.get(0), this.element.querySelector('#jq'), 'Component.$() is a jQuery wrapper around Component.element');
});

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

assert.equal(this.$element.get(0), this.element.querySelector('#child'), 'Component.$(selector) is a jQuery object of the child elements matching selector');
});
assert.equal(this.$element.get(0), this.element.querySelector('#child'), 'Component.$(selector) is a jQuery object of the child elements matching selector');
});
});
28 changes: 0 additions & 28 deletions tests/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,8 @@
import QUnit from 'qunit';
import { registerDeprecationHandler } from '@ember/debug';
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';

let deprecations;

registerDeprecationHandler((message, options, next) => {
// in case a deprecation is issued before a test is started
if (!deprecations) {
deprecations = [];
}

deprecations.push(message);
next(message, options);
});

QUnit.testStart(function() {
deprecations = [];
});

QUnit.assert.noDeprecations = async function(callback) {
let originalDeprecations = deprecations;
deprecations = [];

await callback();
this.deepEqual(deprecations, [], 'Expected no deprecations during test.');

deprecations = originalDeprecations;
};

setApplication(Application.create(config.APP));

start();
12 changes: 11 additions & 1 deletion vendor/jquery/component.dollar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from '@ember/debug';
import { assert, deprecate } from '@ember/debug';

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

deprecate(
'Using this.$() in a component has been deprecated, consider using this.element',
false,
{
id: 'ember-views.curly-components.jquery-element',
until: '4.0.0',
url: 'https://emberjs.com/deprecations/v3.x#toc_jquery-apis',
}
);

if (this.element) {
return sel ? jQuery(sel, this.element) : jQuery(this.element);
}
Expand Down

0 comments on commit c88dbf1

Please sign in to comment.