import 'reflect-metadata'; import { ElementRef, } from '@angular/core'; import { FadeInOnLoadDirective, } from './fade-in-on-load.directive'; const initFadeInOnLoadDirective = ( elementRef?: ElementRef, ) => { return new FadeInOnLoadDirective( elementRef, ); }; describe('ngOnInit', () => { // tslint:disable-next-line test('Adds the correct class to start with', () => { const elementRef = { nativeElement: { classList: {}, }, } as ElementRef; elementRef.nativeElement.classList.add = jest.fn(); const fadeInOnLoadDirective = initFadeInOnLoadDirective( elementRef, ); fadeInOnLoadDirective.ngOnInit(); expect( elementRef.nativeElement.classList.add, ).toHaveBeenCalledWith('u-fade-in-on-load'); }); // tslint:disable-next-line test('Adds the correct class when the image loads', () => { const elementRef = { nativeElement: { classList: {}, }, } as ElementRef; elementRef.nativeElement.classList.add = jest.fn(); const fadeInOnLoadDirective = initFadeInOnLoadDirective( elementRef, ); fadeInOnLoadDirective.ngOnInit(); elementRef.nativeElement.onload(); expect( elementRef.nativeElement.classList.add, ).toHaveBeenCalledWith('u-fade-in-on-load--loaded'); }); });