Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

Commit

Permalink
chore(test): improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin committed Apr 10, 2020
1 parent ca5d66f commit de51a7c
Showing 1 changed file with 55 additions and 16 deletions.
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();
},
});
});
});

0 comments on commit de51a7c

Please sign in to comment.