[DURACOM-240] add and fix tests

This commit is contained in:
Andrea Barbasso
2024-02-27 12:17:47 +01:00
committed by Giuseppe Digilio
parent e1ba78c443
commit 3e30f64e9c
4 changed files with 82 additions and 16 deletions

View File

@@ -1,16 +1,54 @@
import { TestBed } from '@angular/core/testing';
import {
Observable,
of,
} from 'rxjs';
import { MathService } from './math.service';
import {
MathJaxConfig,
MathService,
} from './math.service';
export class MockMathService extends MathService {
protected mathJaxOptions: any = {};
protected mathJax: MathJaxConfig = { source: '', id: '' };
protected mathJaxFallback: MathJaxConfig = { source: '', id: '' };
protected registerMathJaxAsync(config: MathJaxConfig): Promise<any> {
return Promise.resolve();
}
ready(): Observable<boolean> {
return of(true);
}
render(element: HTMLElement): void {
return;
}
}
describe('MathService', () => {
let service: MathService;
let service: MockMathService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(MathService);
service = new MockMathService();
spyOn(service, 'render');
});
it('should be created', () => {
expect(service).toBeTruthy();
});
it('should be ready', (done) => {
service.ready().subscribe(isReady => {
expect(isReady).toBe(true);
done();
});
});
it('should render', () => {
service.render(document.createElement('div'));
expect(service.render).toHaveBeenCalled();
});
});