forked from juristr/angular-testing-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote.service.spec.ts
41 lines (33 loc) · 1012 Bytes
/
remote.service.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* tslint:disable:no-unused-variable */
import {
HttpClientTestingModule,
HttpTestingController
} from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { RemoteService } from './remote.service';
describe('RemoteService', () => {
let service: RemoteService;
let httpMock: HttpTestingController;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [RemoteService]
});
// inject the service
service = TestBed.get(RemoteService);
httpMock = TestBed.get(HttpTestingController);
});
it('should have a service instance', () => {
expect(service).toBeDefined();
});
it('should return the json', () => {
service.fetchViaHttp().subscribe(data => {
expect(data.name).toBe('Juri');
});
const req = httpMock.expectOne('/someendpoint/people.json', 'call to api');
expect(req.request.method).toBe('GET');
req.flush({
name: 'Juri'
});
});
});