質問編集履歴

3

不要なコードの削除

2017/12/26 09:55

投稿

takets
takets

スコア43

test CHANGED
File without changes
test CHANGED
@@ -28,60 +28,6 @@
28
28
 
29
29
  ```typescript
30
30
 
31
- describe('Service: Api', () => {
32
-
33
-
34
-
35
- beforeEach(() => {
36
-
37
- TestBed.configureTestingModule({
38
-
39
- imports: [HttpModule],
40
-
41
- providers: [ApiService, {
42
-
43
- provide: Http,
44
-
45
- useFactory: (backend, options) => new Http(backend, options),
46
-
47
- deps: [MockBackend, BaseRequestOptions]
48
-
49
- }, MockBackend, BaseRequestOptions]
50
-
51
- });
52
-
53
- });
54
-
55
-
56
-
57
- it('userInfo', async(inject([MockBackend, ApiService], (backend: MockBackend, service: ApiService) => {
58
-
59
-
60
-
61
- backend.connections.subscribe((conn: MockConnection) => {
62
-
63
- let ops = new ResponseOptions({body: true});
64
-
65
- conn.mockRespond(new Response(ops));
66
-
67
- });
68
-
69
-
70
-
71
- // isExist APIがtrueを返すことを期待している
72
-
73
- service.isExist().subscribe((res) => {
74
-
75
- expect(res).toBe(true);
76
-
77
- });
78
-
79
-
80
-
81
- })));
82
-
83
- });
84
-
85
31
  ```
86
32
 
87
33
 

2

コードを修正

2017/12/26 09:55

投稿

takets
takets

スコア43

test CHANGED
File without changes
test CHANGED
@@ -26,9 +26,61 @@
26
26
 
27
27
  ###該当のソースコード
28
28
 
29
- ```ここに言語を入力
29
+ ```typescript
30
+
31
+ describe('Service: Api', () => {
30
32
 
31
33
 
34
+
35
+ beforeEach(() => {
36
+
37
+ TestBed.configureTestingModule({
38
+
39
+ imports: [HttpModule],
40
+
41
+ providers: [ApiService, {
42
+
43
+ provide: Http,
44
+
45
+ useFactory: (backend, options) => new Http(backend, options),
46
+
47
+ deps: [MockBackend, BaseRequestOptions]
48
+
49
+ }, MockBackend, BaseRequestOptions]
50
+
51
+ });
52
+
53
+ });
54
+
55
+
56
+
57
+ it('userInfo', async(inject([MockBackend, ApiService], (backend: MockBackend, service: ApiService) => {
58
+
59
+
60
+
61
+ backend.connections.subscribe((conn: MockConnection) => {
62
+
63
+ let ops = new ResponseOptions({body: true});
64
+
65
+ conn.mockRespond(new Response(ops));
66
+
67
+ });
68
+
69
+
70
+
71
+ // isExist APIがtrueを返すことを期待している
72
+
73
+ service.isExist().subscribe((res) => {
74
+
75
+ expect(res).toBe(true);
76
+
77
+ });
78
+
79
+
80
+
81
+ })));
82
+
83
+ });
32
84
 
33
85
  ```
34
86
 

1

コードの修正

2017/12/26 09:49

投稿

takets
takets

スコア43

test CHANGED
File without changes
test CHANGED
@@ -28,124 +28,6 @@
28
28
 
29
29
  ```ここに言語を入力
30
30
 
31
- import { TestBed, inject, async } from '@angular/core/testing';
32
-
33
-
34
-
35
- import { MockBackend, MockConnection } from '@angular/http/testing';
36
-
37
- import {
38
-
39
- Http, HttpModule, Response, ConnectionBackend,
40
-
41
- RequestOptions, BaseRequestOptions, ResponseOptions
42
-
43
- } from '@angular/http';
44
-
45
-
46
-
47
- import { Injectable } from '@angular/core';
48
-
49
- import { ApiService } from './api.service';
50
-
51
-
52
-
53
- describe('APIテスト', () => {
54
-
55
- beforeEach(() => {
56
-
57
- TestBed.configureTestingModule({
58
-
59
- imports: [ HttpModule ],
60
-
61
- providers: [
62
-
63
- {provide: Http, userFactory: (backend, options) => new Http(backend, options), deps: [ MockBackend, BaseRequestOptions ]},
64
-
65
- ApiService,
66
-
67
- MockBackend,
68
-
69
- BaseRequestOptions,
70
-
71
- ]
72
-
73
- });
74
-
75
- });
76
-
77
-
78
-
79
- it('データが存在するか?', async(inject([ MockBackend, ApiService ], (backend: MockBackend, s: ApiService) => {
80
-
81
- backend.connections.subscribe((conn: MockConnection) => {
82
-
83
- const ops = new ResponseOptions({body: true})
84
-
85
- conn.mockRespond(new Response(ops))
86
-
87
- })
88
-
89
-
90
-
91
- s.isExistData('1111', '22', '3333')
92
-
93
- .subscribe(
94
-
95
- (res: boolean) => {
96
-
97
- expect(res).toEqual(true)
98
-
99
- }
100
-
101
- )
102
-
103
- })))
104
-
105
- });
106
-
107
-
108
-
109
- ■APIのコード
110
-
111
- isExistData(v1: string, v2:string, v3:string): Observable<boolean> {
112
-
113
- return Observable.create(observer => {
114
-
115
- const data = {
116
-
117
- v1 : v1,
118
-
119
- v2 : v2,
120
-
121
- v3 : v3,
122
-
123
- }
124
-
125
- this.http.post(environment.apiServer + '/xxxcheck', data)
126
-
127
- .subscribe(
128
-
129
- res => {
130
-
131
- observer.next(res.json()) // trueが返る
132
-
133
- observer.complete()
134
-
135
- },
136
-
137
- error => {
138
-
139
- observer.error(error)
140
-
141
- }
142
-
143
- )
144
-
145
- })
146
-
147
- }
148
-
149
31
 
150
32
 
151
33
  ```