@@ -241,5 +241,92 @@ describe('utils', function() {
241
241
} ) ;
242
242
expect ( log ) . toEqual ( [ 'property1patch' , 'property2<root>' ] ) ;
243
243
} ) ;
244
+
245
+ it ( 'non writable method should not be patched' , ( ) => {
246
+ 'use strict' ;
247
+ const TestFunction : any = function ( ) { } ;
248
+ const log : string [ ] = [ ] ;
249
+ Object . defineProperties ( TestFunction . prototype , {
250
+ 'property2' : {
251
+ value : function Property2 ( callback : Function ) {
252
+ Zone . root . run ( callback ) ;
253
+ } ,
254
+ writable : false ,
255
+ configurable : true ,
256
+ enumerable : true
257
+ }
258
+ } ) ;
259
+
260
+ const zone = Zone . current . fork ( { name : 'patch' } ) ;
261
+
262
+ zone . run ( ( ) => {
263
+ const instance = new TestFunction ( ) ;
264
+ instance . property2 ( ( ) => {
265
+ log . push ( 'property2' + Zone . current . name ) ;
266
+ } ) ;
267
+ } ) ;
268
+ expect ( log ) . toEqual ( [ 'property2<root>' ] ) ;
269
+ log . length = 0 ;
270
+
271
+ patchMethod (
272
+ TestFunction . prototype , 'property2' ,
273
+ function ( delegate : Function , delegateName : string , name : string ) {
274
+ return function ( self : any , args : any ) {
275
+ log . push ( 'patched property2' ) ;
276
+ } ;
277
+ } ) ;
278
+
279
+ zone . run ( ( ) => {
280
+ const instance = new TestFunction ( ) ;
281
+ instance . property2 ( ( ) => {
282
+ log . push ( 'property2' + Zone . current . name ) ;
283
+ } ) ;
284
+ } ) ;
285
+ expect ( log ) . toEqual ( [ 'property2<root>' ] ) ;
286
+ } ) ;
287
+
288
+ it ( 'readonly method should not be patched' , ( ) => {
289
+ 'use strict' ;
290
+ const TestFunction : any = function ( ) { } ;
291
+ const log : string [ ] = [ ] ;
292
+ Object . defineProperties ( TestFunction . prototype , {
293
+ 'property2' : {
294
+ get : function ( ) {
295
+ return function Property2 ( callback : Function ) {
296
+ Zone . root . run ( callback ) ;
297
+ } ;
298
+ } ,
299
+ configurable : true ,
300
+ enumerable : true
301
+ }
302
+ } ) ;
303
+
304
+ const zone = Zone . current . fork ( { name : 'patch' } ) ;
305
+
306
+ zone . run ( ( ) => {
307
+ const instance = new TestFunction ( ) ;
308
+ instance . property2 ( ( ) => {
309
+ log . push ( 'property2' + Zone . current . name ) ;
310
+ } ) ;
311
+ } ) ;
312
+ expect ( log ) . toEqual ( [ 'property2<root>' ] ) ;
313
+ log . length = 0 ;
314
+
315
+ patchMethod (
316
+ TestFunction . prototype , 'property2' ,
317
+ function ( delegate : Function , delegateName : string , name : string ) {
318
+ return function ( self : any , args : any ) {
319
+ log . push ( 'patched property2' ) ;
320
+ } ;
321
+ } ) ;
322
+
323
+ zone . run ( ( ) => {
324
+ const instance = new TestFunction ( ) ;
325
+ instance . property2 ( ( ) => {
326
+ log . push ( 'property2' + Zone . current . name ) ;
327
+ } ) ;
328
+ } ) ;
329
+ expect ( log ) . toEqual ( [ 'property2<root>' ] ) ;
330
+ } ) ;
244
331
} ) ;
245
332
} ) ;
0 commit comments