MCPcopy
hub / github.com/angular/angular / createRouterScroller

Function createRouterScroller

packages/router/test/router_scroller.spec.ts:342–372  ·  view source on GitHub ↗
(
  {
    scrollPositionRestoration,
    anchorScrolling,
  }: {
    scrollPositionRestoration: 'disabled' | 'enabled' | 'top';
    anchorScrolling: 'disabled' | 'enabled';
  },
  extraProviders: any[] = [],
)

Source from the content-addressed store, hash-verified

340});
341
342function createRouterScroller(
343 {
344 scrollPositionRestoration,
345 anchorScrolling,
346 }: {
347 scrollPositionRestoration: 'disabled' | 'enabled' | 'top';
348 anchorScrolling: 'disabled' | 'enabled';
349 },
350 extraProviders: any[] = [],
351) {
352 if (extraProviders.length > 0) {
353 TestBed.configureTestingModule({providers: extraProviders});
354 }
355
356 const events = new Subject<Event | PrivateRouterEvents>();
357 (TestBed.inject(NavigationTransitions) as Writable<NavigationTransitions>).events = events;
358
359 const viewportScroller = TestBed.inject(ViewportScroller);
360 spyOn(viewportScroller, 'getScrollPosition');
361 spyOn(viewportScroller, 'scrollToPosition');
362 spyOn(viewportScroller, 'scrollToAnchor');
363 spyOn(viewportScroller, 'setHistoryScrollRestoration');
364 setScroll(viewportScroller, 0, 0);
365
366 const scroller = TestBed.runInInjectionContext(
367 () => new RouterScroller({scrollPositionRestoration, anchorScrolling}),
368 );
369 scroller.init();
370
371 return {events, viewportScroller};
372}
373
374function setScroll(viewportScroller: any, x: number, y: number) {
375 viewportScroller.getScrollPosition.and.returnValue([x, y]);

Callers 1

Calls 5

setScrollFunction · 0.85
injectMethod · 0.65
runInInjectionContextMethod · 0.65
initMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…