This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,6 +53,39 @@ describe('Zone.countingZone', function () {
5353 } ) ;
5454 } ) ;
5555
56+ it ( 'should work with setInterval' , function ( ) {
57+ var latch = 0 , id ;
58+
59+ runs ( function ( ) {
60+ countingZone . run ( function ( ) {
61+ id = setInterval ( function ( ) {
62+ latch += 1 ;
63+ } , 0 ) ;
64+ expect ( countingZone . counter ( ) ) . toBe ( 1 ) ;
65+ } ) ;
66+ } ) ;
67+
68+ waitsFor ( function ( ) {
69+ return latch === 2 ;
70+ } , 100 , 'latch to increment' ) ;
71+
72+ runs ( function ( ) {
73+ expect ( countingZone . counter ( ) ) . toBe ( 1 ) ;
74+ clearInterval ( id ) ;
75+ } ) ;
76+ } ) ;
77+
78+ it ( 'should work with clearInterval' , function ( ) {
79+ var id ;
80+ countingZone . run ( function ( ) {
81+ id = setInterval ( function ( ) {
82+ latch += 1 ;
83+ } , 0 ) ;
84+ expect ( countingZone . counter ( ) ) . toBe ( 1 ) ;
85+ clearInterval ( id ) ;
86+ expect ( countingZone . counter ( ) ) . toBe ( 0 ) ;
87+ } ) ;
88+ } ) ;
5689
5790 it ( 'should work with addEventListener' , function ( ) {
5891 var elt = document . createElement ( 'button' ) ;
Original file line number Diff line number Diff line change @@ -117,17 +117,32 @@ Zone.patchSetClearFn = function (obj, fnNames) {
117117 if ( delegate ) {
118118 var ids = { } ;
119119
120- zone [ setName ] = function ( fn ) {
121- var id ;
122- arguments [ 0 ] = function ( ) {
123- delete ids [ id ] ;
124- return fn . apply ( this , arguments ) ;
120+ if ( setName === 'setInterval' ) {
121+ zone [ setName ] = function ( fn ) {
122+ var id ;
123+ arguments [ 0 ] = function ( ) {
124+ delete ids [ id ] ;
125+ return fn . apply ( this , arguments ) ;
126+ } ;
127+ var args = Zone . bindArguments ( arguments ) ;
128+ id = delegate . apply ( obj , args ) ;
129+ ids [ id ] = true ;
130+ return id ;
125131 } ;
126- var args = Zone . bindArgumentsOnce ( arguments ) ;
127- id = delegate . apply ( obj , args ) ;
128- ids [ id ] = true ;
129- return id ;
130- } ;
132+ } else {
133+ zone [ setName ] = function ( fn ) {
134+ var id ;
135+ arguments [ 0 ] = function ( ) {
136+ delete ids [ id ] ;
137+ return fn . apply ( this , arguments ) ;
138+ } ;
139+ var args = Zone . bindArgumentsOnce ( arguments ) ;
140+ id = delegate . apply ( obj , args ) ;
141+ ids [ id ] = true ;
142+ return id ;
143+ } ;
144+ }
145+
131146
132147 obj [ setName ] = function ( ) {
133148 return zone [ setName ] . apply ( this , arguments ) ;
You can’t perform that action at this time.
0 commit comments