@@ -2055,27 +2055,15 @@ describe('ngMock', function() {
2055
2055
2056
2056
2057
2057
describe ( '$controllerDecorator' , function ( ) {
2058
- it ( 'should support creating controller with bindings' , function ( ) {
2059
- var called = false ;
2060
- var data = [
2061
- { name : 'derp1' , id : 0 } ,
2062
- { name : 'testname' , id : 1 } ,
2063
- { name : 'flurp' , id : 2 }
2064
- ] ;
2065
- module ( function ( $controllerProvider ) {
2066
- $controllerProvider . register ( 'testCtrl' , function ( ) {
2067
- called = true ;
2068
- expect ( this . data ) . toBe ( data ) ;
2069
- } ) ;
2070
- } ) ;
2071
- inject ( function ( $controller , $rootScope ) {
2072
- $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
2073
- expect ( called ) . toBe ( true ) ;
2074
- } ) ;
2075
- } ) ;
2076
2058
2077
- it ( 'should support assigning bindings when a value is returned from the constructor' ,
2078
- function ( ) {
2059
+ describe ( 'with `preAssignBindingsEnabled(true)`' , function ( ) {
2060
+
2061
+ beforeEach ( module ( function ( $compileProvider ) {
2062
+ $compileProvider . preAssignBindingsEnabled ( true ) ;
2063
+ } ) ) ;
2064
+
2065
+
2066
+ it ( 'should support creating controller with bindings' , function ( ) {
2079
2067
var called = false ;
2080
2068
var data = [
2081
2069
{ name : 'derp1' , id : 0 } ,
@@ -2084,40 +2072,138 @@ describe('ngMock', function() {
2084
2072
] ;
2085
2073
module ( function ( $controllerProvider ) {
2086
2074
$controllerProvider . register ( 'testCtrl' , function ( ) {
2087
- called = true ;
2088
2075
expect ( this . data ) . toBe ( data ) ;
2089
-
2090
- return { } ;
2076
+ called = true ;
2091
2077
} ) ;
2092
2078
} ) ;
2093
2079
inject ( function ( $controller , $rootScope ) {
2094
2080
var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
2095
2081
expect ( ctrl . data ) . toBe ( data ) ;
2096
2082
expect ( called ) . toBe ( true ) ;
2097
2083
} ) ;
2084
+ } ) ;
2085
+
2086
+
2087
+ it ( 'should support assigning bindings when a value is returned from the constructor' ,
2088
+ function ( ) {
2089
+ var called = false ;
2090
+ var data = [
2091
+ { name : 'derp1' , id : 0 } ,
2092
+ { name : 'testname' , id : 1 } ,
2093
+ { name : 'flurp' , id : 2 }
2094
+ ] ;
2095
+ module ( function ( $controllerProvider ) {
2096
+ $controllerProvider . register ( 'testCtrl' , function ( ) {
2097
+ expect ( this . data ) . toBe ( data ) ;
2098
+ called = true ;
2099
+ return { } ;
2100
+ } ) ;
2101
+ } ) ;
2102
+ inject ( function ( $controller , $rootScope ) {
2103
+ var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
2104
+ expect ( ctrl . data ) . toBe ( data ) ;
2105
+ expect ( called ) . toBe ( true ) ;
2106
+ } ) ;
2107
+ }
2108
+ ) ;
2109
+
2110
+
2111
+ if ( / c h r o m e / . test ( window . navigator . userAgent ) ) {
2112
+ it ( 'should support assigning bindings to class-based controller' , function ( ) {
2113
+ var called = false ;
2114
+ var data = [
2115
+ { name : 'derp1' , id : 0 } ,
2116
+ { name : 'testname' , id : 1 } ,
2117
+ { name : 'flurp' , id : 2 }
2118
+ ] ;
2119
+ module ( function ( $controllerProvider ) {
2120
+ // eslint-disable-next-line no-eval
2121
+ var TestCtrl = eval ( '(class { constructor() { called = true; } })' ) ;
2122
+ $controllerProvider . register ( 'testCtrl' , TestCtrl ) ;
2123
+ } ) ;
2124
+ inject ( function ( $controller , $rootScope ) {
2125
+ var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
2126
+ expect ( ctrl . data ) . toBe ( data ) ;
2127
+ expect ( called ) . toBe ( true ) ;
2128
+ } ) ;
2129
+ } ) ;
2098
2130
}
2099
- ) ;
2131
+ } ) ;
2132
+
2100
2133
2101
- if ( / c h r o m e / . test ( window . navigator . userAgent ) ) {
2102
- it ( 'should support assigning bindings to class-based controller' , function ( ) {
2134
+ describe ( 'with `preAssignBindingsEnabled(false)`' , function ( ) {
2135
+
2136
+ beforeEach ( module ( function ( $compileProvider ) {
2137
+ $compileProvider . preAssignBindingsEnabled ( false ) ;
2138
+ } ) ) ;
2139
+
2140
+
2141
+ it ( 'should support creating controller with bindings' , function ( ) {
2103
2142
var called = false ;
2104
2143
var data = [
2105
2144
{ name : 'derp1' , id : 0 } ,
2106
2145
{ name : 'testname' , id : 1 } ,
2107
2146
{ name : 'flurp' , id : 2 }
2108
2147
] ;
2109
2148
module ( function ( $controllerProvider ) {
2110
- // eslint-disable-next-line no-eval
2111
- var TestCtrl = eval ( '(class { constructor() { called = true; } })' ) ;
2112
- $controllerProvider . register ( 'testCtrl' , TestCtrl ) ;
2149
+ $controllerProvider . register ( 'testCtrl' , function ( ) {
2150
+ expect ( this . data ) . toBeUndefined ( ) ;
2151
+ called = true ;
2152
+ } ) ;
2113
2153
} ) ;
2114
2154
inject ( function ( $controller , $rootScope ) {
2115
2155
var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
2116
2156
expect ( ctrl . data ) . toBe ( data ) ;
2117
2157
expect ( called ) . toBe ( true ) ;
2118
2158
} ) ;
2119
2159
} ) ;
2120
- }
2160
+
2161
+
2162
+ it ( 'should support assigning bindings when a value is returned from the constructor' ,
2163
+ function ( ) {
2164
+ var called = false ;
2165
+ var data = [
2166
+ { name : 'derp1' , id : 0 } ,
2167
+ { name : 'testname' , id : 1 } ,
2168
+ { name : 'flurp' , id : 2 }
2169
+ ] ;
2170
+ module ( function ( $controllerProvider ) {
2171
+ $controllerProvider . register ( 'testCtrl' , function ( ) {
2172
+ expect ( this . data ) . toBeUndefined ( ) ;
2173
+ called = true ;
2174
+ return { } ;
2175
+ } ) ;
2176
+ } ) ;
2177
+ inject ( function ( $controller , $rootScope ) {
2178
+ var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
2179
+ expect ( ctrl . data ) . toBe ( data ) ;
2180
+ expect ( called ) . toBe ( true ) ;
2181
+ } ) ;
2182
+ }
2183
+ ) ;
2184
+
2185
+
2186
+ if ( / c h r o m e / . test ( window . navigator . userAgent ) ) {
2187
+ it ( 'should support assigning bindings to class-based controller' , function ( ) {
2188
+ var called = false ;
2189
+ var data = [
2190
+ { name : 'derp1' , id : 0 } ,
2191
+ { name : 'testname' , id : 1 } ,
2192
+ { name : 'flurp' , id : 2 }
2193
+ ] ;
2194
+ module ( function ( $controllerProvider ) {
2195
+ // eslint-disable-next-line no-eval
2196
+ var TestCtrl = eval ( '(class { constructor() { called = true; } })' ) ;
2197
+ $controllerProvider . register ( 'testCtrl' , TestCtrl ) ;
2198
+ } ) ;
2199
+ inject ( function ( $controller , $rootScope ) {
2200
+ var ctrl = $controller ( 'testCtrl' , { scope : $rootScope } , { data : data } ) ;
2201
+ expect ( ctrl . data ) . toBe ( data ) ;
2202
+ expect ( called ) . toBe ( true ) ;
2203
+ } ) ;
2204
+ } ) ;
2205
+ }
2206
+ } ) ;
2121
2207
} ) ;
2122
2208
2123
2209
0 commit comments