1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { fakeAsync, TestBed, tick } from '@angular/core/testing';
4 import { configureTestBed } from '../../../testing/unit-test-helper';
5 import { HostService } from './host.service';
7 describe('HostService', () => {
8 let service: HostService;
9 let httpTesting: HttpTestingController;
12 providers: [HostService],
13 imports: [HttpClientTestingModule]
17 service = TestBed.get(HostService);
18 httpTesting = TestBed.get(HttpTestingController);
25 it('should be created', () => {
26 expect(service).toBeTruthy();
29 it('should call list', fakeAsync(() => {
31 service.list().subscribe((resp) => (result = resp));
32 const req = httpTesting.expectOne('api/host');
33 expect(req.request.method).toBe('GET');
34 req.flush(['foo', 'bar']);
36 expect(result).toEqual(['foo', 'bar']);
39 it('should make a GET request on the devices endpoint when requesting devices', () => {
40 const hostname = 'hostname';
41 service.getDevices(hostname).subscribe();
42 const req = httpTesting.expectOne(`api/host/${hostname}/devices`);
43 expect(req.request.method).toBe('GET');