@@ -4,23 +4,28 @@ import { RxTestScheduler } from '../../src/testing/test-scheduler';
4
4
import { jestMatcher } from '@test-helpers' ;
5
5
import { Subscription , SchedulerAction , merge } from 'rxjs' ;
6
6
import { delay } from 'rxjs/operators' ;
7
- import { AsapAction } from '../../src/scheduler/asap/AsapAction' ;
8
7
import { AsapScheduler } from '../../src/scheduler/asap/AsapScheduler' ;
8
+ import { asapScheduler } from '../../src/scheduler/asap/asap' ;
9
9
10
- let asap : AsapScheduler ;
10
+ const asap : AsapScheduler = asapScheduler ;
11
11
12
12
/** @test {Scheduler} */
13
13
describe ( 'Scheduler.asap' , ( ) => {
14
14
let testScheduler : RxTestScheduler ;
15
+ const proxyZone = window [ 'Zone' ] [ 'ProxyZoneSpec' ] ;
15
16
16
17
beforeEach ( ( ) => {
17
18
testScheduler = new RxTestScheduler ( jestMatcher ) ;
18
- asap = new AsapScheduler ( AsapAction ) ;
19
+ window [ 'Zone' ] [ 'ProxyZoneSpec' ] = undefined ;
19
20
jest . clearAllTimers ( ) ;
20
21
jest . useRealTimers ( ) ;
21
22
jest . clearAllMocks ( ) ;
22
23
} ) ;
23
24
25
+ afterEach ( ( ) => {
26
+ window [ 'Zone' ] [ 'ProxyZoneSpec' ] = proxyZone ;
27
+ } ) ;
28
+
24
29
it ( 'should exist' , ( ) => {
25
30
expect ( asap ) . toBeDefined ( ) ;
26
31
} ) ;
@@ -66,6 +71,10 @@ describe('Scheduler.asap', () => {
66
71
jest . useFakeTimers ( ) ;
67
72
// callThrough is missing from the declarations installed by the typings tool in stable
68
73
const intervalSpy = jest . spyOn ( intervalProvider , 'setInterval' ) ;
74
+ intervalProvider . delegate = {
75
+ setInterval : setInterval ,
76
+ clearInterval : clearInterval ,
77
+ } ;
69
78
const period = 50 ;
70
79
const state = { index : 0 , period } ;
71
80
type State = typeof state ;
@@ -80,17 +89,22 @@ describe('Scheduler.asap', () => {
80
89
expect ( state ) . toHaveProperty ( 'index' , 0 ) ;
81
90
expect ( intervalSpy ) . toHaveBeenCalledTimes ( 1 ) ;
82
91
jest . advanceTimersByTime ( period ) ;
83
- // expect(state).toHaveProperty('index', 1);
92
+ expect ( state ) . toHaveProperty ( 'index' , 1 ) ;
84
93
expect ( intervalSpy ) . toHaveBeenCalledTimes ( 2 ) ;
85
94
jest . advanceTimersByTime ( period ) ;
86
95
expect ( state ) . toHaveProperty ( 'index' , 2 ) ;
87
96
expect ( intervalSpy ) . toHaveBeenCalledTimes ( 3 ) ;
97
+ intervalProvider . delegate = undefined ;
88
98
} ) ;
89
99
90
100
it ( 'should reuse the interval for recursively scheduled actions with the same delay' , ( ) => {
91
101
jest . useFakeTimers ( ) ;
92
102
// callThrough is missing from the declarations installed by the typings tool in stable
93
103
const intervalSpy = jest . spyOn ( intervalProvider , 'setInterval' ) ;
104
+ intervalProvider . delegate = {
105
+ setInterval : setInterval ,
106
+ clearInterval : clearInterval ,
107
+ } ;
94
108
const period = 50 ;
95
109
const state = { index : 0 , period } ;
96
110
type State = typeof state ;
@@ -103,12 +117,13 @@ describe('Scheduler.asap', () => {
103
117
asap . schedule ( dispatch as any , period , state ) ;
104
118
expect ( state ) . toHaveProperty ( 'index' , 0 ) ;
105
119
expect ( intervalSpy ) . toHaveBeenCalledTimes ( 1 ) ;
106
- jest . advanceTimersByTime ( period + 1 ) ;
120
+ jest . advanceTimersByTime ( period ) ;
107
121
expect ( state ) . toHaveProperty ( 'index' , 1 ) ;
108
122
expect ( intervalSpy ) . toHaveBeenCalledTimes ( 1 ) ;
109
123
jest . advanceTimersByTime ( period ) ;
110
124
expect ( state ) . toHaveProperty ( 'index' , 2 ) ;
111
125
expect ( intervalSpy ) . toHaveBeenCalledTimes ( 1 ) ;
126
+ intervalProvider . delegate = undefined ;
112
127
} ) ;
113
128
114
129
it ( 'should schedule an action to happen later' , ( done ) => {
0 commit comments