@@ -1938,6 +1938,125 @@ describe('ngMock', function() {
19381938 expect ( $scope . testCtrl ) . toBe ( ctrl ) ;
19391939 } ) ;
19401940 } ) ;
1941+
1942+ it ( 'should instantiate the controller of the restrict:\'E\' component if there are more directives with the same name but not restricted to \'E\'' , function ( ) {
1943+ function TestController ( ) {
1944+ this . r = 6779 ;
1945+ }
1946+ module ( function ( $compileProvider ) {
1947+ $compileProvider . directive ( 'test' , function ( ) {
1948+ return { restrict : 'A' } ;
1949+ } ) ;
1950+ $compileProvider . component ( 'test' , {
1951+ controller : TestController
1952+ } ) ;
1953+ } ) ;
1954+ inject ( function ( $componentController , $rootScope ) {
1955+ var ctrl = $componentController ( 'test' , { $scope : { } } ) ;
1956+ expect ( ctrl ) . toEqual ( { r : 6779 } ) ;
1957+ } ) ;
1958+ } ) ;
1959+
1960+ it ( 'should instantiate the controller of the restrict:\'E\' component if there are more directives with the same name and restricted to \'E\' but no controller' , function ( ) {
1961+ function TestController ( ) {
1962+ this . r = 22926 ;
1963+ }
1964+ module ( function ( $compileProvider ) {
1965+ $compileProvider . directive ( 'test' , function ( ) {
1966+ return { restrict : 'E' } ;
1967+ } ) ;
1968+ $compileProvider . component ( 'test' , {
1969+ controller : TestController
1970+ } ) ;
1971+ } ) ;
1972+ inject ( function ( $componentController , $rootScope ) {
1973+ var ctrl = $componentController ( 'test' , { $scope : { } } ) ;
1974+ expect ( ctrl ) . toEqual ( { r : 22926 } ) ;
1975+ } ) ;
1976+ } ) ;
1977+
1978+ it ( 'should instantiate the controller of the directive with controller, controllerAs and restrict:\'E\' if there are more directives' , function ( ) {
1979+ function TestController ( ) {
1980+ this . r = 18842 ;
1981+ }
1982+ module ( function ( $compileProvider ) {
1983+ $compileProvider . directive ( 'test' , function ( ) {
1984+ return { } ;
1985+ } ) ;
1986+ $compileProvider . directive ( 'test' , function ( ) {
1987+ return {
1988+ restrict : 'E' ,
1989+ controller : TestController ,
1990+ controllerAs : '$ctrl'
1991+ } ;
1992+ } ) ;
1993+ } ) ;
1994+ inject ( function ( $componentController , $rootScope ) {
1995+ var ctrl = $componentController ( 'test' , { $scope : { } } ) ;
1996+ expect ( ctrl ) . toEqual ( { r : 18842 } ) ;
1997+ } ) ;
1998+ } ) ;
1999+
2000+ it ( 'should fail if there is no directive with restrict:\'E\' and controller' , function ( ) {
2001+ function TestController ( ) {
2002+ this . r = 31145 ;
2003+ }
2004+ module ( function ( $compileProvider ) {
2005+ $compileProvider . directive ( 'test' , function ( ) {
2006+ return {
2007+ restrict : 'AC' ,
2008+ controller : TestController
2009+ } ;
2010+ } ) ;
2011+ $compileProvider . directive ( 'test' , function ( ) {
2012+ return {
2013+ restrict : 'E' ,
2014+ controller : TestController
2015+ } ;
2016+ } ) ;
2017+ $compileProvider . directive ( 'test' , function ( ) {
2018+ return {
2019+ restrict : 'EA' ,
2020+ controller : TestController ,
2021+ controllerAs : '$ctrl'
2022+ } ;
2023+ } ) ;
2024+ $compileProvider . directive ( 'test' , function ( ) {
2025+ return { restrict : 'E' } ;
2026+ } ) ;
2027+ } ) ;
2028+ inject ( function ( $componentController , $rootScope ) {
2029+ expect ( function ( ) {
2030+ $componentController ( 'test' , { $scope : { } } ) ;
2031+ } ) . toThrow ( 'No component found' ) ;
2032+ } ) ;
2033+ } ) ;
2034+
2035+ it ( 'should fail if there more than two components with same name' , function ( ) {
2036+ function TestController ( $scope , a , b ) {
2037+ this . $scope = $scope ;
2038+ this . a = a ;
2039+ this . b = b ;
2040+ }
2041+ module ( function ( $compileProvider ) {
2042+ $compileProvider . directive ( 'test' , function ( ) {
2043+ return {
2044+ restrict : 'E' ,
2045+ controller : TestController ,
2046+ controllerAs : '$ctrl'
2047+ } ;
2048+ } ) ;
2049+ $compileProvider . component ( 'test' , {
2050+ controller : TestController
2051+ } ) ;
2052+ } ) ;
2053+ inject ( function ( $componentController , $rootScope ) {
2054+ expect ( function ( ) {
2055+ var $scope = { } ;
2056+ $componentController ( 'test' , { $scope : $scope , a : 'A' , b : 'B' } , { x : 'X' , y : 'Y' } ) ;
2057+ } ) . toThrow ( 'Too many components found' ) ;
2058+ } ) ;
2059+ } ) ;
19412060 } ) ;
19422061} ) ;
19432062
0 commit comments