8
8
9
9
import { EventEmitter } from '@angular/core' ;
10
10
import { Injectable } from '@angular/core/src/di' ;
11
- import { GetTestability , PendingMacrotask , Testability , TestabilityRegistry } from '@angular/core/src/testability/testability' ;
11
+ import { GetTestability , PendingMacrotask , Testability , TestabilityRegistry , } from '@angular/core/src/testability/testability' ;
12
12
import { NgZone } from '@angular/core/src/zone/ng_zone' ;
13
13
import { fakeAsync , tick , waitForAsync } from '@angular/core/testing' ;
14
14
@@ -25,8 +25,11 @@ function microTask(fn: Function): void {
25
25
26
26
class NoopGetTestability implements GetTestability {
27
27
addToWindow ( registry : TestabilityRegistry ) : void { }
28
- findTestabilityInTree ( registry : TestabilityRegistry , elem : any , findInAncestors : boolean ) :
29
- Testability | null {
28
+ findTestabilityInTree (
29
+ registry : TestabilityRegistry ,
30
+ elem : any ,
31
+ findInAncestors : boolean ,
32
+ ) : Testability | null {
30
33
return null ;
31
34
}
32
35
}
@@ -77,62 +80,6 @@ describe('Testability', () => {
77
80
// (injected into a constructor) across all instances.
78
81
setTestabilityGetter ( null ! as GetTestability ) ;
79
82
} ) ;
80
- describe ( 'Pending count logic' , ( ) => {
81
- it ( 'should start with a pending count of 0' , ( ) => {
82
- expect ( testability . getPendingRequestCount ( ) ) . toEqual ( 0 ) ;
83
- } ) ;
84
-
85
- it ( 'should fire whenstable callbacks if pending count is 0' , waitForAsync ( ( ) => {
86
- testability . whenStable ( execute ) ;
87
-
88
- microTask ( ( ) => {
89
- expect ( execute ) . toHaveBeenCalled ( ) ;
90
- } ) ;
91
- } ) ) ;
92
-
93
- it ( 'should not fire whenstable callbacks synchronously if pending count is 0' , ( ) => {
94
- testability . whenStable ( execute ) ;
95
- expect ( execute ) . not . toHaveBeenCalled ( ) ;
96
- } ) ;
97
-
98
- it ( 'should not call whenstable callbacks when there are pending counts' , waitForAsync ( ( ) => {
99
- testability . increasePendingRequestCount ( ) ;
100
- testability . increasePendingRequestCount ( ) ;
101
- testability . whenStable ( execute ) ;
102
-
103
- microTask ( ( ) => {
104
- expect ( execute ) . not . toHaveBeenCalled ( ) ;
105
- testability . decreasePendingRequestCount ( ) ;
106
-
107
- microTask ( ( ) => {
108
- expect ( execute ) . not . toHaveBeenCalled ( ) ;
109
- } ) ;
110
- } ) ;
111
- } ) ) ;
112
-
113
- it ( 'should fire whenstable callbacks when pending drops to 0' , waitForAsync ( ( ) => {
114
- testability . increasePendingRequestCount ( ) ;
115
- testability . whenStable ( execute ) ;
116
-
117
- microTask ( ( ) => {
118
- expect ( execute ) . not . toHaveBeenCalled ( ) ;
119
- testability . decreasePendingRequestCount ( ) ;
120
-
121
- microTask ( ( ) => {
122
- expect ( execute ) . toHaveBeenCalled ( ) ;
123
- } ) ;
124
- } ) ;
125
- } ) ) ;
126
-
127
- it ( 'should not fire whenstable callbacks synchronously when pending drops to 0' ,
128
- waitForAsync ( ( ) => {
129
- testability . increasePendingRequestCount ( ) ;
130
- testability . whenStable ( execute ) ;
131
- testability . decreasePendingRequestCount ( ) ;
132
-
133
- expect ( execute ) . not . toHaveBeenCalled ( ) ;
134
- } ) ) ;
135
- } ) ;
136
83
137
84
describe ( 'NgZone callback logic' , ( ) => {
138
85
describe ( 'whenStable with timeout' , ( ) => {
@@ -159,7 +106,7 @@ describe('Testability', () => {
159
106
160
107
it ( 'calls the done callback when angular is stable' , fakeAsync ( ( ) => {
161
108
let timeout1Done = false ;
162
- ngZone . run ( ( ) => setTimeout ( ( ) => timeout1Done = true , 500 ) ) ;
109
+ ngZone . run ( ( ) => setTimeout ( ( ) => ( timeout1Done = true ) , 500 ) ) ;
163
110
testability . whenStable ( execute , 1000 ) ;
164
111
165
112
tick ( 600 ) ;
@@ -176,16 +123,15 @@ describe('Testability', () => {
176
123
expect ( execute . calls . count ( ) ) . toEqual ( 1 ) ;
177
124
} ) ) ;
178
125
179
-
180
126
it ( 'calls update when macro tasks change' , fakeAsync ( ( ) => {
181
127
let timeout1Done = false ;
182
128
let timeout2Done = false ;
183
- ngZone . run ( ( ) => setTimeout ( ( ) => timeout1Done = true , 500 ) ) ;
129
+ ngZone . run ( ( ) => setTimeout ( ( ) => ( timeout1Done = true ) , 500 ) ) ;
184
130
tick ( ) ;
185
131
testability . whenStable ( execute , 1000 , updateCallback ) ;
186
132
187
133
tick ( 100 ) ;
188
- ngZone . run ( ( ) => setTimeout ( ( ) => timeout2Done = true , 300 ) ) ;
134
+ ngZone . run ( ( ) => setTimeout ( ( ) => ( timeout2Done = true ) , 300 ) ) ;
189
135
expect ( updateCallback . calls . count ( ) ) . toEqual ( 1 ) ;
190
136
tick ( 600 ) ;
191
137
@@ -209,7 +155,7 @@ describe('Testability', () => {
209
155
testability . whenStable ( execute , 1000 , execute2 ) ;
210
156
211
157
tick ( 100 ) ;
212
- ngZone . run ( ( ) => setTimeout ( ( ) => timeoutDone = true , 500 ) ) ;
158
+ ngZone . run ( ( ) => setTimeout ( ( ) => ( timeoutDone = true ) , 500 ) ) ;
213
159
ngZone . stable ( ) ;
214
160
expect ( execute2 ) . toHaveBeenCalled ( ) ;
215
161
@@ -258,43 +204,33 @@ describe('Testability', () => {
258
204
expect ( execute ) . not . toHaveBeenCalled ( ) ;
259
205
} ) ;
260
206
261
- it ( 'should not fire whenstable callback when event did not finish' , fakeAsync ( ( ) => {
207
+ it ( 'should fire whenstable callback with didWork if event is already finished' ,
208
+ fakeAsync ( ( ) => {
262
209
ngZone . unstable ( ) ;
263
- testability . increasePendingRequestCount ( ) ;
210
+ ngZone . stable ( ) ;
264
211
testability . whenStable ( execute ) ;
265
212
266
213
tick ( ) ;
267
- expect ( execute ) . not . toHaveBeenCalled ( ) ;
268
- testability . decreasePendingRequestCount ( ) ;
269
-
270
- tick ( ) ;
271
- expect ( execute ) . not . toHaveBeenCalled ( ) ;
272
- ngZone . stable ( ) ;
214
+ expect ( execute ) . toHaveBeenCalled ( ) ;
215
+ testability . whenStable ( execute2 ) ;
273
216
274
217
tick ( ) ;
275
- expect ( execute ) . toHaveBeenCalled ( ) ;
218
+ expect ( execute2 ) . toHaveBeenCalled ( ) ;
276
219
} ) ) ;
277
220
278
- it ( 'should not fire whenstable callback when there are pending counts ' , fakeAsync ( ( ) => {
221
+ it ( 'should fire whenstable callback with didwork when event finishes ' , fakeAsync ( ( ) => {
279
222
ngZone . unstable ( ) ;
280
- testability . increasePendingRequestCount ( ) ;
281
- testability . increasePendingRequestCount ( ) ;
282
223
testability . whenStable ( execute ) ;
283
224
284
225
tick ( ) ;
285
- expect ( execute ) . not . toHaveBeenCalled ( ) ;
286
226
ngZone . stable ( ) ;
287
227
288
228
tick ( ) ;
289
- expect ( execute ) . not . toHaveBeenCalled ( ) ;
290
- testability . decreasePendingRequestCount ( ) ;
291
-
292
- tick ( ) ;
293
- expect ( execute ) . not . toHaveBeenCalled ( ) ;
294
- testability . decreasePendingRequestCount ( ) ;
229
+ expect ( execute ) . toHaveBeenCalled ( ) ;
230
+ testability . whenStable ( execute2 ) ;
295
231
296
232
tick ( ) ;
297
- expect ( execute ) . toHaveBeenCalled ( ) ;
233
+ expect ( execute2 ) . toHaveBeenCalled ( ) ;
298
234
} ) ) ;
299
235
} ) ;
300
236
} ) ;
0 commit comments