|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {ddescribe, describe, it} from '@angular/core/testing/src/testing_internal'; |
| 9 | +import {ddescribe, describe, iit, it} from '@angular/core/testing/src/testing_internal'; |
10 | 10 | import {Observable} from 'rxjs/Observable';
|
11 | 11 |
|
12 | 12 | import {HttpRequest} from '../src/request';
|
@@ -87,14 +87,22 @@ export function main() {
|
87 | 87 | });
|
88 | 88 | it('handles a json response', () => {
|
89 | 89 | const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
|
90 |
| - factory.mock.mockFlush(200, 'OK', {data: 'some data'}); |
| 90 | + factory.mock.mockFlush(200, 'OK', JSON.stringify({data: 'some data'})); |
91 | 91 | expect(events.length).toBe(2);
|
92 | 92 | const res = events[1] as HttpResponse<{data: string}>;
|
93 | 93 | expect(res.body !.data).toBe('some data');
|
94 | 94 | });
|
95 |
| - it('handles a json response that comes via responseText', () => { |
| 95 | + it('handles a json string response', () => { |
96 | 96 | const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
|
97 |
| - factory.mock.mockFlush(200, 'OK', JSON.stringify({data: 'some data'})); |
| 97 | + expect(factory.mock.responseType).toEqual('text'); |
| 98 | + factory.mock.mockFlush(200, 'OK', JSON.stringify('this is a string')); |
| 99 | + expect(events.length).toBe(2); |
| 100 | + const res = events[1] as HttpResponse<string>; |
| 101 | + expect(res.body).toEqual('this is a string'); |
| 102 | + }); |
| 103 | + it('handles a json response with an XSSI prefix', () => { |
| 104 | + const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'}))); |
| 105 | + factory.mock.mockFlush(200, 'OK', ')]}\'\n' + JSON.stringify({data: 'some data'})); |
98 | 106 | expect(events.length).toBe(2);
|
99 | 107 | const res = events[1] as HttpResponse<{data: string}>;
|
100 | 108 | expect(res.body !.data).toBe('some data');
|
@@ -299,7 +307,7 @@ export function main() {
|
299 | 307 | expect(error.status).toBe(0);
|
300 | 308 | done();
|
301 | 309 | });
|
302 |
| - factory.mock.mockFlush(0, 'CORS 0 status', null); |
| 310 | + factory.mock.mockFlush(0, 'CORS 0 status'); |
303 | 311 | });
|
304 | 312 | });
|
305 | 313 | });
|
|
0 commit comments