@@ -3,19 +3,28 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
33
44import { ScrollReveal } from './scroll-reveal' ;
55
6- class MockIntersectionObserver {
6+ class MockIntersectionObserver implements IntersectionObserver {
7+ readonly #callback: IntersectionObserverCallback ;
8+
79 static last : MockIntersectionObserver | undefined ;
810
11+ readonly root = null ;
12+ readonly rootMargin = '' ;
13+ readonly scrollMargin = '' ;
14+ readonly thresholds : readonly number [ ] = [ ] ;
15+
916 readonly observe = vi . fn ( ) ;
10- readonly #callback: IntersectionObserverCallback ;
17+ readonly unobserve = vi . fn ( ) ;
18+ readonly disconnect = vi . fn ( ) ;
19+ readonly takeRecords = vi . fn < ( ) => IntersectionObserverEntry [ ] > ( ( ) => [ ] ) ;
1120
1221 constructor ( callback : IntersectionObserverCallback ) {
1322 this . #callback = callback ;
1423 MockIntersectionObserver . last = this ;
1524 }
1625
1726 fire ( isIntersecting : boolean ) : void {
18- this . #callback( [ { isIntersecting } as IntersectionObserverEntry ] , this as unknown as IntersectionObserver ) ;
27+ this . #callback( [ { isIntersecting } as IntersectionObserverEntry ] , this ) ;
1928 }
2029}
2130
@@ -44,7 +53,11 @@ describe('ScrollReveal', () => {
4453 TestBed . tick ( ) ;
4554
4655 const target : HTMLElement = fixture . nativeElement . querySelector ( '.target' ) ;
47- const observer = MockIntersectionObserver . last ! ;
56+ const observer = MockIntersectionObserver . last ;
57+
58+ if ( ! observer ) {
59+ throw new Error ( 'IntersectionObserver was not created' ) ;
60+ }
4861
4962 expect ( target . classList . contains ( 'reveal' ) ) . toBe ( true ) ;
5063 expect ( observer . observe ) . toHaveBeenCalledWith ( target ) ;
0 commit comments