import { ElementRef, } from '@angular/core'; const mockScrollIntoView = jest.fn(); jest.mock('scroll-into-view', () => mockScrollIntoView); import { ScrollIntoViewOnInitDirective, } from './scroll-into-view-on-init.directive'; const initScrollIntoViewOnInitDirective = ( elementRef: ElementRef, ) => { return new ScrollIntoViewOnInitDirective( elementRef, ); }; describe('ngOnInit', () => { test('Calls scrollIntoView on elementRef', () => { const elementRef = { nativeElement: {}, } as ElementRef; mockScrollIntoView.mockReset(); const scrollIntoViewOnInit = initScrollIntoViewOnInitDirective(elementRef); scrollIntoViewOnInit.ngOnInit(); expect(mockScrollIntoView) .toHaveBeenCalledWith(elementRef.nativeElement); }); });