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
42
43
44
45
46
47
48
49
50
51
52
53
54
|
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { toArray } from 'rxjs/operators';
import { TodoItem } from '../todo-item';
import { TodoService, IssueResponse } from './todo.service';
describe('TodoService', () => {
beforeEach(() => TestBed.configureTestingModule({
imports: [HttpClientTestingModule]
}));
it('should be created', () => {
const service: TodoService = TestBed.get(TodoService);
expect(service).toBeTruthy();
});
it('should work well', () => {
const service: TodoService = TestBed.get(TodoService);
const baseUrl = service.baseUrl;
const mockIssueList: IssueResponse = [{
number: 1,
title: 'Issue title 1',
state: 'open',
html_url: 'test_url1'
}, {
number: 2,
title: 'Issue title 2',
state: 'closed',
html_url: 'test_url2',
pull_request: {}
}];
const mockTodoItemList: TodoItem[] = [{
number: 1,
title: 'Issue title 1',
isClosed: false,
detailUrl: 'test_url1'
}];
service.getWorkItemList().pipe(toArray()).subscribe(data => {
expect(data).toEqual(mockTodoItemList);
});
const httpController: HttpTestingController = TestBed.get(HttpTestingController);
httpController.expectOne(request => request.url === baseUrl + '/issues' && request.params.get('state') === 'all').flush(mockIssueList);
httpController.verify();
});
});
|