Skip to content

Commit 87dc851

Browse files
martiansnoopthePunderWoman
authored andcommitted
fix(upgrade): preserve $interval.flush when ngMocks is being used (#30229)
Also preserve any other properties that the user may have decorated $interval with. PR Close #30229
1 parent 17bae32 commit 87dc851

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/upgrade/static/src/upgrade_module.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ import {NgAdapterInjector} from './util';
116116
*
117117
* {@example upgrade/static/ts/full/module.ts region='bootstrap-ng1'}
118118
*
119-
* Finally, kick off the whole process, by bootstraping your top level Angular `NgModule`.
119+
* Finally, kick off the whole process, by bootstrapping your top level Angular `NgModule`.
120120
*
121121
* {@example upgrade/static/ts/full/module.ts region='bootstrap-ng2'}
122122
*
@@ -236,7 +236,17 @@ export class UpgradeModule {
236236
});
237237
};
238238

239-
(wrappedInterval as any)['cancel'] = intervalDelegate.cancel;
239+
(Object.keys(intervalDelegate) as (keyof IIntervalService)[])
240+
.forEach(prop => (wrappedInterval as any)[prop] = intervalDelegate[prop]);
241+
242+
// the `flush` method will be present when ngMocks is used
243+
if (intervalDelegate.hasOwnProperty('flush')) {
244+
(wrappedInterval as any)['flush'] = () => {
245+
(intervalDelegate as any)['flush']();
246+
return wrappedInterval;
247+
};
248+
}
249+
240250
return wrappedInterval;
241251
}
242252
]);

0 commit comments

Comments
 (0)