Skip to content

Commit

Permalink
fix(upgrade): preserve $interval.flush when ngMocks is being used (#3…
Browse files Browse the repository at this point in the history
…0229)

Also preserve any other properties that the user may have decorated
$interval with.

PR Close #30229
  • Loading branch information
martiansnoop authored and thePunderWoman committed Apr 23, 2021
1 parent 17bae32 commit 87dc851
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/upgrade/static/src/upgrade_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ import {NgAdapterInjector} from './util';
*
* {@example upgrade/static/ts/full/module.ts region='bootstrap-ng1'}
*
* Finally, kick off the whole process, by bootstraping your top level Angular `NgModule`.
* Finally, kick off the whole process, by bootstrapping your top level Angular `NgModule`.
*
* {@example upgrade/static/ts/full/module.ts region='bootstrap-ng2'}
*
Expand Down Expand Up @@ -236,7 +236,17 @@ export class UpgradeModule {
});
};

(wrappedInterval as any)['cancel'] = intervalDelegate.cancel;
(Object.keys(intervalDelegate) as (keyof IIntervalService)[])
.forEach(prop => (wrappedInterval as any)[prop] = intervalDelegate[prop]);

// the `flush` method will be present when ngMocks is used
if (intervalDelegate.hasOwnProperty('flush')) {
(wrappedInterval as any)['flush'] = () => {
(intervalDelegate as any)['flush']();
return wrappedInterval;
};
}

return wrappedInterval;
}
]);
Expand Down

0 comments on commit 87dc851

Please sign in to comment.