@@ -225,6 +225,96 @@ describe('$compile', function() {
225
225
} ) ;
226
226
inject ( function ( $compile ) { } ) ;
227
227
} ) ;
228
+
229
+ it ( 'should preserve context within declaration' , function ( ) {
230
+ module ( function ( ) {
231
+ directive ( 'ff' , function ( log ) {
232
+ var declaration = {
233
+ restrict : 'E' ,
234
+ template : function ( ) {
235
+ log ( 'ff template: ' + ( this === declaration ) ) ;
236
+ } ,
237
+ compile : function ( ) {
238
+ log ( 'ff compile: ' + ( this === declaration ) ) ;
239
+ return function ( ) {
240
+ log ( 'ff post: ' + ( this === declaration ) ) ;
241
+ } ;
242
+ }
243
+ } ;
244
+ return declaration ;
245
+ } ) ;
246
+
247
+ directive ( 'fff' , function ( log ) {
248
+ var declaration = {
249
+ restrict : 'E' ,
250
+ link : {
251
+ pre : function ( ) {
252
+ log ( 'fff pre: ' + ( this === declaration ) ) ;
253
+ } ,
254
+ post : function ( ) {
255
+ log ( 'fff post: ' + ( this === declaration ) ) ;
256
+ }
257
+ }
258
+ } ;
259
+ return declaration ;
260
+ } ) ;
261
+
262
+ directive ( 'ffff' , function ( log ) {
263
+ var declaration = {
264
+ restrict : 'E' ,
265
+ compile : function ( ) {
266
+ return {
267
+ pre : function ( ) {
268
+ log ( 'ffff pre: ' + ( this === declaration ) ) ;
269
+ } ,
270
+ post : function ( ) {
271
+ log ( 'ffff post: ' + ( this === declaration ) ) ;
272
+ }
273
+ } ;
274
+ }
275
+ } ;
276
+ return declaration ;
277
+ } ) ;
278
+
279
+ directive ( 'fffff' , function ( log ) {
280
+ var declaration = {
281
+ restrict : 'E' ,
282
+ templateUrl : function ( ) {
283
+ log ( 'fffff: ' + ( this === declaration ) ) ;
284
+ }
285
+ } ;
286
+ return declaration ;
287
+ } ) ;
288
+
289
+ directive ( 'ffffff' , function ( log ) {
290
+ var declaration = {
291
+ restrict : 'E' ,
292
+ link : function ( ) {
293
+ log ( 'ffffff: ' + ( this === declaration ) ) ;
294
+ }
295
+ } ;
296
+ return declaration ;
297
+ } ) ;
298
+ } ) ;
299
+ inject ( function ( $compile , $rootScope , log ) {
300
+ $compile ( '<ff></ff>' ) ( $rootScope ) ;
301
+ $compile ( '<fff></fff>' ) ( $rootScope ) ;
302
+ $compile ( '<ffff></ffff>' ) ( $rootScope ) ;
303
+ $compile ( '<fffff></fffff>' ) ( $rootScope ) ;
304
+ $compile ( '<ffffff></ffffff>' ) ( $rootScope ) ;
305
+ expect ( log ) . toEqual (
306
+ 'ff template: true; ' +
307
+ 'ff compile: true; ' +
308
+ 'ff post: true; ' +
309
+ 'fff pre: true; ' +
310
+ 'fff post: true; ' +
311
+ 'ffff pre: true; ' +
312
+ 'ffff post: true; ' +
313
+ 'fffff: true; ' +
314
+ 'ffffff: true'
315
+ ) ;
316
+ } ) ;
317
+ } ) ;
228
318
} ) ;
229
319
230
320
0 commit comments