This repository has been archived by the owner on May 29, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca5d66f
commit de51a7c
Showing
1 changed file
with
55 additions
and
16 deletions.
There are no files selected for viewing
71 changes: 55 additions & 16 deletions
71
projects/resize-observer/src/services/tests/resize-observer.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,63 @@ | ||
import {NgZone} from '@angular/core'; | ||
import {ElementRef} from '@angular/core'; | ||
import {TestBed} from '@angular/core/testing'; | ||
import {catchError} from 'rxjs/operators'; | ||
import {RESIZE_OBSERVER_SUPPORT} from '../../tokens/support'; | ||
import {ResizeObserverService} from '../resize-observer.service'; | ||
|
||
describe('ResizeObserverService', () => { | ||
it('throws when not supported', () => { | ||
let error = false; | ||
const service = new ResizeObserverService( | ||
{ | ||
nativeElement: document.createElement('DIV'), | ||
}, | ||
new NgZone({}), | ||
false, | ||
'content-box', | ||
describe('Resize Observer token', () => { | ||
let service: ResizeObserverService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
ResizeObserverService, | ||
|
||
{ | ||
provide: ElementRef, | ||
useValue: { | ||
nativeElement: document.createElement('DIV'), | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
service = TestBed.get(ResizeObserverService).pipe( | ||
catchError((_err, caught) => caught), | ||
); | ||
}); | ||
|
||
service.subscribe({ | ||
error: () => { | ||
error = true; | ||
}, | ||
it('defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('throws when not supported', () => { | ||
it('Throws an error if ResizeObserver is not supported', done => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
ResizeObserverService, | ||
|
||
{ | ||
provide: ElementRef, | ||
useValue: { | ||
nativeElement: document.createElement('DIV'), | ||
}, | ||
}, | ||
{ | ||
provide: RESIZE_OBSERVER_SUPPORT, | ||
useValue: false, | ||
}, | ||
], | ||
}); | ||
|
||
expect(error).toBe(true); | ||
const service$: ResizeObserverService = TestBed.get(ResizeObserverService); | ||
|
||
service$.subscribe({ | ||
error: err => { | ||
expect(err).toBe('ResizeObserver is not supported in your browser'); | ||
|
||
done(); | ||
}, | ||
}); | ||
}); | ||
}); |