diff --git a/src/app/core/server-check/server-check.guard.spec.ts b/src/app/core/server-check/server-check.guard.spec.ts index 13045b0ff6..f18b386753 100644 --- a/src/app/core/server-check/server-check.guard.spec.ts +++ b/src/app/core/server-check/server-check.guard.spec.ts @@ -63,16 +63,18 @@ describe('ServerCheckGuard', () => { }); describe(`listenForRouteChanges`, () => { - it(`should invalidate the root cache on every NavigationStart event`, () => { + it(`should invalidate the root cache when the method is first called, and then on every NavigationStart event`, () => { testScheduler.run(() => { guard.listenForRouteChanges(); + expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(1); + eventSubject.next(new NavigationStart(1,'')); eventSubject.next(new NavigationEnd(1,'', '')); eventSubject.next(new NavigationStart(2,'')); eventSubject.next(new NavigationEnd(2,'', '')); eventSubject.next(new NavigationStart(3,'')); }); - expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(3); + expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(4); }); }); }); diff --git a/src/app/core/server-check/server-check.guard.ts b/src/app/core/server-check/server-check.guard.ts index ab3bc2c6e9..1cea5f36ba 100644 --- a/src/app/core/server-check/server-check.guard.ts +++ b/src/app/core/server-check/server-check.guard.ts @@ -52,6 +52,10 @@ export class ServerCheckGuard implements CanActivateChild { * operation, the cached version is used. */ listenForRouteChanges(): void { + // we'll always be too late for the first NavigationStart event with the router subscribe below, + // so this statement is for the very first route operation + this.rootDataService.invalidateRootCache(); + this.router.events.pipe( filter(event => event instanceof NavigationStart), ).subscribe(() => {