Skip to content

Commit e1ee6f4

Browse files
petebacondarwinNarretz
authored andcommitted
test($compile): check explicit return controllers are not broken by binding require
1 parent 6f395ea commit e1ee6f4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/ng/compileSpec.js

+49
Original file line numberDiff line numberDiff line change
@@ -5381,6 +5381,55 @@ describe('$compile', function() {
53815381
});
53825382
});
53835383

5384+
it('should bind required controllers to controller that has an explicit constructor return value', function() {
5385+
var parentController, siblingController, meController;
5386+
5387+
function ParentController() { this.name = 'Parent'; }
5388+
function SiblingController() { this.name = 'Sibling'; }
5389+
function MeController() {
5390+
meController = {
5391+
name: 'Me',
5392+
$onInit: function() {
5393+
parentController = this.container;
5394+
siblingController = this.friend;
5395+
}
5396+
};
5397+
spyOn(meController, '$onInit').andCallThrough();
5398+
return meController;
5399+
}
5400+
5401+
angular.module('my', [])
5402+
.directive('me', function() {
5403+
return {
5404+
restrict: 'E',
5405+
scope: {},
5406+
require: { container: '^parent', friend: 'sibling' },
5407+
controller: MeController
5408+
};
5409+
})
5410+
.directive('parent', function() {
5411+
return {
5412+
restrict: 'E',
5413+
scope: {},
5414+
controller: ParentController
5415+
};
5416+
})
5417+
.directive('sibling', function() {
5418+
return {
5419+
controller: SiblingController
5420+
};
5421+
});
5422+
5423+
module('my');
5424+
inject(function($compile, $rootScope, meDirective) {
5425+
element = $compile('<parent><me sibling></me></parent>')($rootScope);
5426+
expect(meController.$onInit).toHaveBeenCalled();
5427+
expect(parentController).toEqual(jasmine.any(ParentController));
5428+
expect(siblingController).toEqual(jasmine.any(SiblingController));
5429+
});
5430+
});
5431+
5432+
53845433
it('should require controller of an isolate directive from a non-isolate directive on the ' +
53855434
'same element', function() {
53865435
var IsolateController = function() {};

0 commit comments

Comments
 (0)