@@ -132,21 +132,135 @@ describe('ngHintScopes', function() {
132
132
} ) ;
133
133
} ) ;
134
134
135
- // describe('$rootScope.$apply', function() {
136
- // it('should fire a message when called', function() {
137
- // var scope = $rootScope.$new ();
138
- // spyOn(hint, 'emit' );
135
+ describe ( '$rootScope.$apply' , function ( ) {
136
+ beforeEach ( function ( ) {
137
+ jasmine . clock ( ) . install ( ) ;
138
+ } ) ;
139
139
140
- // scope.$apply();
140
+ afterEach ( function ( ) {
141
+ jasmine . clock ( ) . uninstall ( ) ;
142
+ } ) ;
141
143
142
- // expect(hint.emit).toHaveBeenCalled();
143
- // var args = hint.emit.calls[1].args;
144
+ // it('should fire a message when called', function() {
145
+ // var scope = $rootScope.$new();
146
+ // spyOn(hint, 'emit');
144
147
145
- // expect(args[0]).toBe('scope:apply');
146
- // expect(args[1].id).toBe(scope.$id);
147
- // expect(args[1].time).toBeDefined();
148
- // });
149
- // });
148
+ // scope.$apply();
149
+
150
+ // expect(hint.emit).toHaveBeenCalled();
151
+ // var args = hint.emit.calls[1].args;
152
+
153
+ // expect(args[0]).toBe('scope:apply');
154
+ // expect(args[1].id).toBe(scope.$id);
155
+ // expect(args[1].time).toBeDefined();
156
+ // });
157
+
158
+ it ( 'should cause model:change events to be emitted for all paths on current scope' , function ( ) {
159
+ var scope = $rootScope . $new ( ) ;
160
+ scope . a = { b : { c : 1 } } ;
161
+ hint . watch ( scope . $id , 'a.b.c' ) ;
162
+ jasmine . clock ( ) . tick ( 10 ) ;
163
+ spyOn ( hint , 'emit' ) ;
164
+ scope . a . b . c = 2 ;
165
+ scope . $apply ( ) ;
166
+ jasmine . clock ( ) . tick ( 10 ) ;
167
+
168
+ expect ( hint . emit . calls . count ( ) ) . toEqual ( 3 ) ;
169
+
170
+ var args = getArgsOfNthCall ( 0 ) ;
171
+ expect ( args [ 0 ] ) . toBe ( 'scope:digest' ) ;
172
+
173
+ args = getArgsOfNthCall ( 1 ) ;
174
+ expect ( args [ 0 ] ) . toBe ( 'model:change' ) ;
175
+ expect ( args [ 1 ] ) . toEqual ( {
176
+ id : scope . $id ,
177
+ path : 'a.b' ,
178
+ oldValue : '{"c":1}' ,
179
+ value : '{"c":2}'
180
+ } ) ;
181
+
182
+ args = getArgsOfNthCall ( 2 ) ;
183
+ expect ( args [ 0 ] ) . toBe ( 'model:change' ) ;
184
+ expect ( args [ 1 ] ) . toEqual ( {
185
+ id : scope . $id ,
186
+ path : 'a.b.c' ,
187
+ oldValue : 1 ,
188
+ value : 2
189
+ } ) ;
190
+ } ) ;
191
+
192
+ it ( 'should cause model:change events to be emitted for all other watched scopes' , function ( ) {
193
+ var parentScope = $rootScope . $new ( ) ;
194
+ var targetScope = parentScope . $new ( ) ;
195
+ var childScope = targetScope . $new ( ) ;
196
+ var siblingScope = parentScope . $new ( ) ;
197
+
198
+ parentScope . a = 1 ;
199
+ childScope . b = 1 ;
200
+ siblingScope . c = 1 ;
201
+
202
+ hint . watch ( parentScope . $id , 'a' ) ;
203
+ hint . watch ( childScope . $id , 'b' ) ;
204
+ hint . watch ( siblingScope . $id , 'c' ) ;
205
+ jasmine . clock ( ) . tick ( 10 ) ;
206
+ spyOn ( hint , 'emit' ) ;
207
+ parentScope . a = 2 ;
208
+ childScope . b = 2 ;
209
+ siblingScope . c = 2 ;
210
+ targetScope . $apply ( ) ;
211
+ jasmine . clock ( ) . tick ( 10 ) ;
212
+
213
+ expect ( hint . emit . calls . count ( ) ) . toEqual ( 4 ) ;
214
+
215
+ var args = getArgsOfNthCall ( 0 ) ;
216
+ expect ( args [ 0 ] ) . toBe ( 'scope:digest' ) ;
217
+
218
+ args = getArgsOfNthCall ( 1 ) ;
219
+ expect ( args [ 0 ] ) . toBe ( 'model:change' ) ;
220
+ expect ( args [ 1 ] ) . toEqual ( {
221
+ id : parentScope . $id ,
222
+ path : 'a' ,
223
+ oldValue : 1 ,
224
+ value : 2
225
+ } ) ;
226
+
227
+ args = getArgsOfNthCall ( 2 ) ;
228
+ expect ( args [ 0 ] ) . toBe ( 'model:change' ) ;
229
+ expect ( args [ 1 ] ) . toEqual ( {
230
+ id : childScope . $id ,
231
+ path : 'b' ,
232
+ oldValue : 1 ,
233
+ value : 2
234
+ } ) ;
235
+
236
+ args = getArgsOfNthCall ( 3 ) ;
237
+ expect ( args [ 0 ] ) . toBe ( 'model:change' ) ;
238
+ expect ( args [ 1 ] ) . toEqual ( {
239
+ id : siblingScope . $id ,
240
+ path : 'c' ,
241
+ oldValue : 1 ,
242
+ value : 2
243
+ } ) ;
244
+ } ) ;
245
+
246
+ it ( 'should maintain the data type of the $id for the current angular version' , function ( ) {
247
+ var targetScope = $rootScope . $new ( ) ;
248
+ targetScope . a = 1 ;
249
+ hint . watch ( targetScope . $id , 'a' ) ;
250
+ jasmine . clock ( ) . tick ( 10 ) ;
251
+ spyOn ( hint , 'emit' ) ;
252
+ targetScope . a = 2 ;
253
+
254
+ targetScope . $apply ( ) ;
255
+ jasmine . clock ( ) . tick ( 10 ) ;
256
+
257
+ var args = getArgsOfNthCall ( 1 ) ;
258
+ expect ( args [ 0 ] ) . toBe ( 'model:change' ) ;
259
+
260
+ // expect strings for angular 1.2, integers for 1.3+
261
+ expect ( args [ 1 ] . id ) . toBe ( targetScope . $id ) ;
262
+ } ) ;
263
+ } ) ;
150
264
151
265
describe ( 'hint.watch' , function ( ) {
152
266
var scope ;
0 commit comments