From 6c5a05ad49a1e083570c3dfe331403398f899dbe Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Thu, 15 Mar 2012 13:40:00 -0700
Subject: feat(jqLite): add .controller() method
extend JQuery with .controller() method which retrieves the closest controller for a given element
---
test/jqLiteSpec.js | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
(limited to 'test/jqLiteSpec.js')
diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js
index 5b2e35b0..5cad8c24 100644
--- a/test/jqLiteSpec.js
+++ b/test/jqLiteSpec.js
@@ -140,8 +140,8 @@ describe('jqLite', function() {
describe('injector', function() {
it('should retrieve injector attached to the current element or its parent', function() {
var template = jqLite('
'),
- span = template.children().eq(0),
- injector = angular.bootstrap(template);
+ span = template.children().eq(0),
+ injector = angular.bootstrap(template);
expect(span.injector()).toBe(injector);
@@ -150,6 +150,27 @@ describe('jqLite', function() {
});
+ describe('controller', function() {
+ it('should retrieve controller attached to the current element or its parent', function() {
+ var div = jqLite('
'),
+ span = div.find('span');
+
+ div.data('$ngControllerController', 'ngController');
+ span.data('$otherController', 'other');
+
+ expect(span.controller()).toBe('ngController');
+ expect(span.controller('ngController')).toBe('ngController');
+ expect(span.controller('other')).toBe('other');
+
+ expect(div.controller()).toBe('ngController');
+ expect(div.controller('ngController')).toBe('ngController');
+ expect(div.controller('other')).toBe(undefined);
+
+ dealoc(div);
+ });
+ });
+
+
describe('data', function() {
it('should set and get and remove data', function() {
var selected = jqLite([a, b, c]);
--
cgit v1.2.3