Skip to content

Commit

Permalink
Merge pull request #10530 from rwjblue/assert-on-tagless-view-jquery-…
Browse files Browse the repository at this point in the history
…usage

[BUGFIX beta] Add assertion when calling this.$() in a tagless view.
  • Loading branch information
stefanpenner committed Feb 25, 2015
2 parents 25e679b + 871aa64 commit 877dc97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/ember-views/lib/views/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ var View = CoreView.extend(
@return {jQuery} the jQuery object for the DOM node
*/
$: function(sel) {
Ember.assert('You cannot access this.$() on a component with `tagName: \'\'` specified.', this.tagName !== '');
return this.currentState.$(this, sel);
},

Expand Down
27 changes: 17 additions & 10 deletions packages/ember-views/tests/views/view/jquery_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { get } from "ember-metal/property_get";
import run from "ember-metal/run_loop";
import EmberView from "ember-views/views/view";
import { runAppend, runDestroy } from "ember-runtime/tests/utils";

var view;
QUnit.module("EmberView#$", {
Expand All @@ -11,15 +11,11 @@ QUnit.module("EmberView#$", {
}
}).create();

run(function() {
view.append();
});
runAppend(view);
},

teardown: function() {
run(function() {
view.destroy();
});
runDestroy(view);
}
});

Expand All @@ -29,9 +25,7 @@ QUnit.test("returns undefined if no element", function() {
equal(view.$(), undefined, 'should return undefined');
equal(view.$('span'), undefined, 'should undefined if filter passed');

run(function() {
view.destroy();
});
runDestroy(view);
});

QUnit.test("returns jQuery object selecting element if provided", function() {
Expand All @@ -57,3 +51,16 @@ QUnit.test("returns empty jQuery object if filter passed that does not match ite
equal(jquery.length, 0, 'view.$(body) should have no elements');
});

QUnit.test("asserts for tagless views", function() {
var view = EmberView.create({
tagName: ''
});

runAppend(view);

expectAssertion(function() {
view.$();
}, /You cannot access this.\$\(\) on a component with `tagName: \'\'` specified/);

runDestroy(view);
});

0 comments on commit 877dc97

Please sign in to comment.