Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Add assertion when calling this.$() in a tagless view. #10530

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});