11aba5dbd0
Signed-off-by: Gato <cedric@goutailler-olivier.fr>
38 lines
1005 B
TypeScript
38 lines
1005 B
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { TestBed } from '@angular/core/testing';
|
|
import { of } from 'rxjs';
|
|
import { vi } from 'vitest';
|
|
import { VersionApiService } from './version-api.service';
|
|
|
|
describe('VersionApiService', () => {
|
|
let service: VersionApiService;
|
|
let httpGetMock: ReturnType<typeof vi.fn>;
|
|
|
|
beforeEach(() => {
|
|
httpGetMock = vi.fn();
|
|
|
|
TestBed.configureTestingModule({
|
|
providers: [
|
|
VersionApiService,
|
|
{ provide: HttpClient, useValue: { get: httpGetMock } },
|
|
],
|
|
});
|
|
|
|
service = TestBed.inject(VersionApiService);
|
|
});
|
|
|
|
it('should be created', () => {
|
|
expect(service).toBeTruthy();
|
|
});
|
|
|
|
it('calls GET /api/version and returns the response', () => {
|
|
httpGetMock.mockReturnValue(of({ version: '1.2.3' }));
|
|
|
|
let result: any;
|
|
service.getVersion().subscribe((r) => (result = r));
|
|
|
|
expect(httpGetMock).toHaveBeenCalledWith('/api/version');
|
|
expect(result).toEqual({ version: '1.2.3' });
|
|
});
|
|
});
|