@@ -1857,6 +1857,88 @@ describe('ngMock', function() {
18571857 } ) ;
18581858 } ) ;
18591859 } ) ;
1860+
1861+
1862+ describe ( '$componentController' , function ( ) {
1863+ it ( 'should instantiate a simple controller defined inline in a component' , function ( ) {
1864+ function TestController ( $scope , a , b ) {
1865+ this . $scope = $scope ;
1866+ this . a = a ;
1867+ this . b = b ;
1868+ }
1869+ module ( function ( $compileProvider ) {
1870+ $compileProvider . component ( 'test' , {
1871+ controller : TestController
1872+ } ) ;
1873+ } ) ;
1874+ inject ( function ( $componentController , $rootScope ) {
1875+ var $scope = { } ;
1876+ var ctrl = $componentController ( 'test' , { $scope : $scope , a : 'A' , b : 'B' } , { x : 'X' , y : 'Y' } ) ;
1877+ expect ( ctrl ) . toEqual ( { $scope : $scope , a : 'A' , b : 'B' , x : 'X' , y : 'Y' } ) ;
1878+ expect ( $scope . $ctrl ) . toBe ( ctrl ) ;
1879+ } ) ;
1880+ } ) ;
1881+
1882+ it ( 'should instantiate a controller with $$inject annotation defined inline in a component' , function ( ) {
1883+ function TestController ( x , y , z ) {
1884+ this . $scope = x ;
1885+ this . a = y ;
1886+ this . b = z ;
1887+ }
1888+ TestController . $inject = [ '$scope' , 'a' , 'b' ] ;
1889+ module ( function ( $compileProvider ) {
1890+ $compileProvider . component ( 'test' , {
1891+ controller : TestController
1892+ } ) ;
1893+ } ) ;
1894+ inject ( function ( $componentController , $rootScope ) {
1895+ var $scope = { } ;
1896+ var ctrl = $componentController ( 'test' , { $scope : $scope , a : 'A' , b : 'B' } , { x : 'X' , y : 'Y' } ) ;
1897+ expect ( ctrl ) . toEqual ( { $scope : $scope , a : 'A' , b : 'B' , x : 'X' , y : 'Y' } ) ;
1898+ expect ( $scope . $ctrl ) . toBe ( ctrl ) ;
1899+ } ) ;
1900+ } ) ;
1901+
1902+ it ( 'should instantiate a named controller defined in a component' , function ( ) {
1903+ function TestController ( $scope , a , b ) {
1904+ this . $scope = $scope ;
1905+ this . a = a ;
1906+ this . b = b ;
1907+ }
1908+ module ( function ( $controllerProvider , $compileProvider ) {
1909+ $controllerProvider . register ( 'TestController' , TestController ) ;
1910+ $compileProvider . component ( 'test' , {
1911+ controller : 'TestController'
1912+ } ) ;
1913+ } ) ;
1914+ inject ( function ( $componentController , $rootScope ) {
1915+ var $scope = { } ;
1916+ var ctrl = $componentController ( 'test' , { $scope : $scope , a : 'A' , b : 'B' } , { x : 'X' , y : 'Y' } ) ;
1917+ expect ( ctrl ) . toEqual ( { $scope : $scope , a : 'A' , b : 'B' , x : 'X' , y : 'Y' } ) ;
1918+ expect ( $scope . $ctrl ) . toBe ( ctrl ) ;
1919+ } ) ;
1920+ } ) ;
1921+
1922+ it ( 'should instantiate a named controller with `controller as` syntax defined in a component' , function ( ) {
1923+ function TestController ( $scope , a , b ) {
1924+ this . $scope = $scope ;
1925+ this . a = a ;
1926+ this . b = b ;
1927+ }
1928+ module ( function ( $controllerProvider , $compileProvider ) {
1929+ $controllerProvider . register ( 'TestController' , TestController ) ;
1930+ $compileProvider . component ( 'test' , {
1931+ controller : 'TestController as testCtrl'
1932+ } ) ;
1933+ } ) ;
1934+ inject ( function ( $componentController , $rootScope ) {
1935+ var $scope = { } ;
1936+ var ctrl = $componentController ( 'test' , { $scope : $scope , a : 'A' , b : 'B' } , { x : 'X' , y : 'Y' } ) ;
1937+ expect ( ctrl ) . toEqual ( { $scope : $scope , a : 'A' , b : 'B' , x : 'X' , y : 'Y' } ) ;
1938+ expect ( $scope . testCtrl ) . toBe ( ctrl ) ;
1939+ } ) ;
1940+ } ) ;
1941+ } ) ;
18601942} ) ;
18611943
18621944
0 commit comments