File tree Expand file tree Collapse file tree
packages/core/test/emulate Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,19 @@ export function mockClock() {
1515
1616 registerCleanupTask ( ( ) => jasmine . clock ( ) . uninstall ( ) )
1717
18+ const pendingMicroTasks : Array < ( ) => void > = [ ]
19+
20+ const originalPromiseResolve = Promise . resolve . bind ( Promise )
21+ spyOn ( Promise , 'resolve' ) . and . callFake (
22+ ( ) =>
23+ ( {
24+ then : ( callback : ( ) => void ) => {
25+ pendingMicroTasks . push ( callback )
26+ return originalPromiseResolve ( )
27+ } ,
28+ } ) as Promise < void >
29+ )
30+
1831 return {
1932 /**
2033 * Returns a RelativeTime representing the time it was X milliseconds after the `mockClock()`
@@ -26,7 +39,10 @@ export function mockClock() {
2639 * invokation (the start of the test).
2740 */
2841 timeStamp : ( duration : number ) => ( timeStampStart + duration ) as TimeStamp ,
29- tick : ( ms : number ) => jasmine . clock ( ) . tick ( ms ) ,
42+ tick : ( ms : number ) => {
43+ pendingMicroTasks . splice ( 0 ) . forEach ( ( task ) => task ( ) )
44+ jasmine . clock ( ) . tick ( ms )
45+ } ,
3046 setDate : ( date : Date ) => jasmine . clock ( ) . mockDate ( date ) ,
3147 }
3248}
You can’t perform that action at this time.
0 commit comments