@@ -1947,27 +1947,15 @@ describe('ngMock', function() {
1947
1947
1948
1948
1949
1949
describe ( '$controllerDecorator' , function ( ) {
1950
- it ( 'should support creating controller with bindings' , function ( ) {
1951
- var called = false ;
1952
- var data = [
1953
- { name : 'derp1' , id : 0 } ,
1954
- { name : 'testname' , id : 1 } ,
1955
- { name : 'flurp' , id : 2 }
1956
- ] ;
1957
- module ( function ( $controllerProvider ) {
1958
- $controllerProvider . register ( 'testCtrl' , function ( ) {
1959
- called = true ;
1960
- expect ( this . data ) . toBe ( data ) ;
1961
- } ) ;
1962
- } ) ;
1963
- inject ( function ( $controller , $rootScope ) {
1964
- $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
1965
- expect ( called ) . toBe ( true ) ;
1966
- } ) ;
1967
- } ) ;
1968
1950
1969
- it ( 'should support assigning bindings when a value is returned from the constructor' ,
1970
- function ( ) {
1951
+ describe ( 'with `preAssignBindingsEnabled(true)`' , function ( ) {
1952
+
1953
+ beforeEach ( module ( function ( $compileProvider ) {
1954
+ $compileProvider . preAssignBindingsEnabled ( true ) ;
1955
+ } ) ) ;
1956
+
1957
+
1958
+ it ( 'should support creating controller with bindings' , function ( ) {
1971
1959
var called = false ;
1972
1960
var data = [
1973
1961
{ name : 'derp1' , id : 0 } ,
@@ -1976,40 +1964,138 @@ describe('ngMock', function() {
1976
1964
] ;
1977
1965
module ( function ( $controllerProvider ) {
1978
1966
$controllerProvider . register ( 'testCtrl' , function ( ) {
1979
- called = true ;
1980
1967
expect ( this . data ) . toBe ( data ) ;
1981
-
1982
- return { } ;
1968
+ called = true ;
1983
1969
} ) ;
1984
1970
} ) ;
1985
1971
inject ( function ( $controller , $rootScope ) {
1986
1972
var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
1987
1973
expect ( ctrl . data ) . toBe ( data ) ;
1988
1974
expect ( called ) . toBe ( true ) ;
1989
1975
} ) ;
1976
+ } ) ;
1977
+
1978
+
1979
+ it ( 'should support assigning bindings when a value is returned from the constructor' ,
1980
+ function ( ) {
1981
+ var called = false ;
1982
+ var data = [
1983
+ { name : 'derp1' , id : 0 } ,
1984
+ { name : 'testname' , id : 1 } ,
1985
+ { name : 'flurp' , id : 2 }
1986
+ ] ;
1987
+ module ( function ( $controllerProvider ) {
1988
+ $controllerProvider . register ( 'testCtrl' , function ( ) {
1989
+ expect ( this . data ) . toBe ( data ) ;
1990
+ called = true ;
1991
+ return { } ;
1992
+ } ) ;
1993
+ } ) ;
1994
+ inject ( function ( $controller , $rootScope ) {
1995
+ var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
1996
+ expect ( ctrl . data ) . toBe ( data ) ;
1997
+ expect ( called ) . toBe ( true ) ;
1998
+ } ) ;
1999
+ }
2000
+ ) ;
2001
+
2002
+
2003
+ if ( / c h r o m e / . test ( window . navigator . userAgent ) ) {
2004
+ it ( 'should support assigning bindings to class-based controller' , function ( ) {
2005
+ var called = false ;
2006
+ var data = [
2007
+ { name : 'derp1' , id : 0 } ,
2008
+ { name : 'testname' , id : 1 } ,
2009
+ { name : 'flurp' , id : 2 }
2010
+ ] ;
2011
+ module ( function ( $controllerProvider ) {
2012
+ // eslint-disable-next-line no-eval
2013
+ var TestCtrl = eval ( '(class { constructor() { called = true; } })' ) ;
2014
+ $controllerProvider . register ( 'testCtrl' , TestCtrl ) ;
2015
+ } ) ;
2016
+ inject ( function ( $controller , $rootScope ) {
2017
+ var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
2018
+ expect ( ctrl . data ) . toBe ( data ) ;
2019
+ expect ( called ) . toBe ( true ) ;
2020
+ } ) ;
2021
+ } ) ;
1990
2022
}
1991
- ) ;
2023
+ } ) ;
2024
+
1992
2025
1993
- if ( / c h r o m e / . test ( window . navigator . userAgent ) ) {
1994
- it ( 'should support assigning bindings to class-based controller' , function ( ) {
2026
+ describe ( 'with `preAssignBindingsEnabled(false)`' , function ( ) {
2027
+
2028
+ beforeEach ( module ( function ( $compileProvider ) {
2029
+ $compileProvider . preAssignBindingsEnabled ( false ) ;
2030
+ } ) ) ;
2031
+
2032
+
2033
+ it ( 'should support creating controller with bindings' , function ( ) {
1995
2034
var called = false ;
1996
2035
var data = [
1997
2036
{ name : 'derp1' , id : 0 } ,
1998
2037
{ name : 'testname' , id : 1 } ,
1999
2038
{ name : 'flurp' , id : 2 }
2000
2039
] ;
2001
2040
module ( function ( $controllerProvider ) {
2002
- // eslint-disable-next-line no-eval
2003
- var TestCtrl = eval ( '(class { constructor() { called = true; } })' ) ;
2004
- $controllerProvider . register ( 'testCtrl' , TestCtrl ) ;
2041
+ $controllerProvider . register ( 'testCtrl' , function ( ) {
2042
+ expect ( this . data ) . toBeUndefined ( ) ;
2043
+ called = true ;
2044
+ } ) ;
2005
2045
} ) ;
2006
2046
inject ( function ( $controller , $rootScope ) {
2007
2047
var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
2008
2048
expect ( ctrl . data ) . toBe ( data ) ;
2009
2049
expect ( called ) . toBe ( true ) ;
2010
2050
} ) ;
2011
2051
} ) ;
2012
- }
2052
+
2053
+
2054
+ it ( 'should support assigning bindings when a value is returned from the constructor' ,
2055
+ function ( ) {
2056
+ var called = false ;
2057
+ var data = [
2058
+ { name : 'derp1' , id : 0 } ,
2059
+ { name : 'testname' , id : 1 } ,
2060
+ { name : 'flurp' , id : 2 }
2061
+ ] ;
2062
+ module ( function ( $controllerProvider ) {
2063
+ $controllerProvider . register ( 'testCtrl' , function ( ) {
2064
+ expect ( this . data ) . toBeUndefined ( ) ;
2065
+ called = true ;
2066
+ return { } ;
2067
+ } ) ;
2068
+ } ) ;
2069
+ inject ( function ( $controller , $rootScope ) {
2070
+ var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
2071
+ expect ( ctrl . data ) . toBe ( data ) ;
2072
+ expect ( called ) . toBe ( true ) ;
2073
+ } ) ;
2074
+ }
2075
+ ) ;
2076
+
2077
+
2078
+ if ( / c h r o m e / . test ( window . navigator . userAgent ) ) {
2079
+ it ( 'should support assigning bindings to class-based controller' , function ( ) {
2080
+ var called = false ;
2081
+ var data = [
2082
+ { name : 'derp1' , id : 0 } ,
2083
+ { name : 'testname' , id : 1 } ,
2084
+ { name : 'flurp' , id : 2 }
2085
+ ] ;
2086
+ module ( function ( $controllerProvider ) {
2087
+ // eslint-disable-next-line no-eval
2088
+ var TestCtrl = eval ( '(class { constructor() { called = true; } })' ) ;
2089
+ $controllerProvider . register ( 'testCtrl' , TestCtrl ) ;
2090
+ } ) ;
2091
+ inject ( function ( $controller , $rootScope ) {
2092
+ var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
2093
+ expect ( ctrl . data ) . toBe ( data ) ;
2094
+ expect ( called ) . toBe ( true ) ;
2095
+ } ) ;
2096
+ } ) ;
2097
+ }
2098
+ } ) ;
2013
2099
} ) ;
2014
2100
2015
2101
0 commit comments