Skip to content

Commit

Permalink
Add test for no deprecations, fixed Ember.Component.$ implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
simonihmig committed Jan 23, 2019
1 parent 15e93e3 commit 2e8509b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
10 changes: 2 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const EMBER_VERSION_WITH_JQUERY_DEPRECATION = '3.9.0'; // @todo replace with real version
const EMBER_VERSION_WITH_JQUERY_DEPRECATION = '3.9.0-canary';

module.exports = {
name: require('./package').name,
Expand Down Expand Up @@ -50,12 +50,6 @@ module.exports = {
files: ['jquery.js'],
});

let babelAddon = this.project.findAddonByName('ember-cli-babel');
let es6Tree = new Funnel(path.join(__dirname, 'vendor/jquery'), {
destDir: 'jquery',
});
let transpiledTree = babelAddon.transpileTree(es6Tree);

return new BroccoliMergeTrees([jquery, tree, transpiledTree], { overwrite: true });
return new BroccoliMergeTrees([jquery, tree]);
},
};
Empty file removed tests/integration/.gitkeep
Empty file.
20 changes: 12 additions & 8 deletions tests/integration/components/component-dot-dollar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ module('Integration | Component | component-dot-dollar', function(hooks) {
this.setJQueryElement = ($) => this.$element = $;
});

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

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: 28 additions & 0 deletions tests/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
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();
8 changes: 2 additions & 6 deletions vendor/jquery/component.dollar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import Component from '@ember/component';
import jQuery from 'jquery';
import { assert } from '@ember/debug';

Component.reopen({
Ember.Component.reopen({
$(sel) {
assert(
Ember.assert(
"You cannot access this.$() on a component with `tagName: ''` specified.",
this.tagName !== ''
);
Expand Down

0 comments on commit 2e8509b

Please sign in to comment.