@@ -1938,6 +1938,116 @@ describe('ngMock', function() {
1938
1938
expect ( $scope . testCtrl ) . toBe ( ctrl ) ;
1939
1939
} ) ;
1940
1940
} ) ;
1941
+
1942
+ it ( 'should instantiate the controller of the restrict:\'E\' component if there are more directives with the same name but not \'E\' restrictness' , 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 \'E\' restrictness 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 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
+ controller : TestController ,
1989
+ controllerAs : '$ctrl'
1990
+ } ;
1991
+ } ) ;
1992
+ } ) ;
1993
+ inject ( function ( $componentController , $rootScope ) {
1994
+ var ctrl = $componentController ( 'test' , { $scope : { } } ) ;
1995
+ expect ( ctrl ) . toEqual ( { r : 18842 } ) ;
1996
+ } ) ;
1997
+ } ) ;
1998
+
1999
+ it ( 'should fail if there is no directive with restrict:\'E\' compatible and controller' , function ( ) {
2000
+ function TestController ( ) {
2001
+ this . r = 31145 ;
2002
+ }
2003
+ module ( function ( $compileProvider ) {
2004
+ $compileProvider . directive ( 'test' , function ( ) {
2005
+ return {
2006
+ restrict : 'AC' ,
2007
+ controller : TestController
2008
+ } ;
2009
+ } ) ;
2010
+ $compileProvider . directive ( 'test' , function ( ) {
2011
+ return {
2012
+ restrict : 'E' ,
2013
+ controller : TestController
2014
+ } ;
2015
+ } ) ;
2016
+ $compileProvider . directive ( 'test' , function ( ) {
2017
+ return { restrict : 'E' } ;
2018
+ } ) ;
2019
+ } ) ;
2020
+ inject ( function ( $componentController , $rootScope ) {
2021
+ expect ( function ( ) {
2022
+ $componentController ( 'test' , { $scope : { } } ) ;
2023
+ } ) . toThrow ( 'No component found' ) ;
2024
+ } ) ;
2025
+ } ) ;
2026
+
2027
+ it ( 'should fail if there more than two components with same name' , function ( ) {
2028
+ function TestController ( $scope , a , b ) {
2029
+ this . $scope = $scope ;
2030
+ this . a = a ;
2031
+ this . b = b ;
2032
+ }
2033
+ module ( function ( $compileProvider ) {
2034
+ $compileProvider . directive ( 'test' , function ( ) {
2035
+ return {
2036
+ controller : TestController ,
2037
+ controllerAs : '$ctrl'
2038
+ } ;
2039
+ } ) ;
2040
+ $compileProvider . component ( 'test' , {
2041
+ controller : TestController
2042
+ } ) ;
2043
+ } ) ;
2044
+ inject ( function ( $componentController , $rootScope ) {
2045
+ expect ( function ( ) {
2046
+ var $scope = { } ;
2047
+ $componentController ( 'test' , { $scope : $scope , a : 'A' , b : 'B' } , { x : 'X' , y : 'Y' } ) ;
2048
+ } ) . toThrow ( 'Too many components found' ) ;
2049
+ } ) ;
2050
+ } ) ;
1941
2051
} ) ;
1942
2052
} ) ;
1943
2053
0 commit comments