Front end of the Slack clone application.

http-testing.umd.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/http'), require('rxjs/ReplaySubject'), require('rxjs/Subject'), require('rxjs/operator/take')) :
  8. typeof define === 'function' && define.amd ? define('@angular/http/testing', ['exports', '@angular/core', '@angular/http', 'rxjs/ReplaySubject', 'rxjs/Subject', 'rxjs/operator/take'], factory) :
  9. (factory((global.ng = global.ng || {}, global.ng.http = global.ng.http || {}, global.ng.http.testing = {}),global.ng.core,global.ng.http,global.Rx,global.Rx,global.Rx.Observable.prototype));
  10. }(this, (function (exports,_angular_core,_angular_http,rxjs_ReplaySubject,rxjs_Subject,rxjs_operator_take) { 'use strict';
  11. /**
  12. * @license Angular v5.2.11
  13. * (c) 2010-2018 Google, Inc. https://angular.io/
  14. * License: MIT
  15. */
  16. /**
  17. * @fileoverview added by tsickle
  18. * @suppress {checkTypes} checked by tsc
  19. */
  20. /**
  21. * @license
  22. * Copyright Google Inc. All Rights Reserved.
  23. *
  24. * Use of this source code is governed by an MIT-style license that can be
  25. * found in the LICENSE file at https://angular.io/license
  26. */
  27. /**
  28. *
  29. * Mock Connection to represent a {\@link Connection} for tests.
  30. *
  31. * @deprecated use \@angular/common/http instead
  32. */
  33. var MockConnection = /** @class */ (function () {
  34. function MockConnection(req) {
  35. this.response = /** @type {?} */ (rxjs_operator_take.take.call(new rxjs_ReplaySubject.ReplaySubject(1), 1));
  36. this.readyState = _angular_http.ReadyState.Open;
  37. this.request = req;
  38. }
  39. /**
  40. * Sends a mock response to the connection. This response is the value that is emitted to the
  41. * {@link EventEmitter} returned by {@link Http}.
  42. *
  43. * ### Example
  44. *
  45. * ```
  46. * var connection;
  47. * backend.connections.subscribe(c => connection = c);
  48. * http.request('data.json').subscribe(res => console.log(res.text()));
  49. * connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs
  50. * 'fake response'
  51. * ```
  52. *
  53. */
  54. /**
  55. * Sends a mock response to the connection. This response is the value that is emitted to the
  56. * {\@link EventEmitter} returned by {\@link Http}.
  57. *
  58. * ### Example
  59. *
  60. * ```
  61. * var connection;
  62. * backend.connections.subscribe(c => connection = c);
  63. * http.request('data.json').subscribe(res => console.log(res.text()));
  64. * connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs
  65. * 'fake response'
  66. * ```
  67. *
  68. * @param {?} res
  69. * @return {?}
  70. */
  71. MockConnection.prototype.mockRespond = /**
  72. * Sends a mock response to the connection. This response is the value that is emitted to the
  73. * {\@link EventEmitter} returned by {\@link Http}.
  74. *
  75. * ### Example
  76. *
  77. * ```
  78. * var connection;
  79. * backend.connections.subscribe(c => connection = c);
  80. * http.request('data.json').subscribe(res => console.log(res.text()));
  81. * connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs
  82. * 'fake response'
  83. * ```
  84. *
  85. * @param {?} res
  86. * @return {?}
  87. */
  88. function (res) {
  89. if (this.readyState === _angular_http.ReadyState.Done || this.readyState === _angular_http.ReadyState.Cancelled) {
  90. throw new Error('Connection has already been resolved');
  91. }
  92. this.readyState = _angular_http.ReadyState.Done;
  93. this.response.next(res);
  94. this.response.complete();
  95. };
  96. /**
  97. * Not yet implemented!
  98. *
  99. * Sends the provided {@link Response} to the `downloadObserver` of the `Request`
  100. * associated with this connection.
  101. */
  102. /**
  103. * Not yet implemented!
  104. *
  105. * Sends the provided {\@link Response} to the `downloadObserver` of the `Request`
  106. * associated with this connection.
  107. * @param {?} res
  108. * @return {?}
  109. */
  110. MockConnection.prototype.mockDownload = /**
  111. * Not yet implemented!
  112. *
  113. * Sends the provided {\@link Response} to the `downloadObserver` of the `Request`
  114. * associated with this connection.
  115. * @param {?} res
  116. * @return {?}
  117. */
  118. function (res) {
  119. // this.request.downloadObserver.onNext(res);
  120. // if (res.bytesLoaded === res.totalBytes) {
  121. // this.request.downloadObserver.onCompleted();
  122. // }
  123. };
  124. // TODO(jeffbcross): consider using Response type
  125. /**
  126. * Emits the provided error object as an error to the {@link Response} {@link EventEmitter}
  127. * returned
  128. * from {@link Http}.
  129. *
  130. * ### Example
  131. *
  132. * ```
  133. * var connection;
  134. * backend.connections.subscribe(c => connection = c);
  135. * http.request('data.json').subscribe(res => res, err => console.log(err)));
  136. * connection.mockError(new Error('error'));
  137. * ```
  138. *
  139. */
  140. /**
  141. * Emits the provided error object as an error to the {\@link Response} {\@link EventEmitter}
  142. * returned
  143. * from {\@link Http}.
  144. *
  145. * ### Example
  146. *
  147. * ```
  148. * var connection;
  149. * backend.connections.subscribe(c => connection = c);
  150. * http.request('data.json').subscribe(res => res, err => console.log(err)));
  151. * connection.mockError(new Error('error'));
  152. * ```
  153. *
  154. * @param {?=} err
  155. * @return {?}
  156. */
  157. MockConnection.prototype.mockError = /**
  158. * Emits the provided error object as an error to the {\@link Response} {\@link EventEmitter}
  159. * returned
  160. * from {\@link Http}.
  161. *
  162. * ### Example
  163. *
  164. * ```
  165. * var connection;
  166. * backend.connections.subscribe(c => connection = c);
  167. * http.request('data.json').subscribe(res => res, err => console.log(err)));
  168. * connection.mockError(new Error('error'));
  169. * ```
  170. *
  171. * @param {?=} err
  172. * @return {?}
  173. */
  174. function (err) {
  175. // Matches ResourceLoader semantics
  176. this.readyState = _angular_http.ReadyState.Done;
  177. this.response.error(err);
  178. };
  179. return MockConnection;
  180. }());
  181. /**
  182. * A mock backend for testing the {\@link Http} service.
  183. *
  184. * This class can be injected in tests, and should be used to override providers
  185. * to other backends, such as {\@link XHRBackend}.
  186. *
  187. * ### Example
  188. *
  189. * ```
  190. * import {Injectable, Injector} from '\@angular/core';
  191. * import {async, fakeAsync, tick} from '\@angular/core/testing';
  192. * import {BaseRequestOptions, ConnectionBackend, Http, RequestOptions} from '\@angular/http';
  193. * import {Response, ResponseOptions} from '\@angular/http';
  194. * import {MockBackend, MockConnection} from '\@angular/http/testing';
  195. *
  196. * const HERO_ONE = 'HeroNrOne';
  197. * const HERO_TWO = 'WillBeAlwaysTheSecond';
  198. *
  199. * \@Injectable()
  200. * class HeroService {
  201. * constructor(private http: Http) {}
  202. *
  203. * getHeroes(): Promise<String[]> {
  204. * return this.http.get('myservices.de/api/heroes')
  205. * .toPromise()
  206. * .then(response => response.json().data)
  207. * .catch(e => this.handleError(e));
  208. * }
  209. *
  210. * private handleError(error: any): Promise<any> {
  211. * console.error('An error occurred', error);
  212. * return Promise.reject(error.message || error);
  213. * }
  214. * }
  215. *
  216. * describe('MockBackend HeroService Example', () => {
  217. * beforeEach(() => {
  218. * this.injector = Injector.create([
  219. * {provide: ConnectionBackend, useClass: MockBackend},
  220. * {provide: RequestOptions, useClass: BaseRequestOptions},
  221. * Http,
  222. * HeroService,
  223. * ]);
  224. * this.heroService = this.injector.get(HeroService);
  225. * this.backend = this.injector.get(ConnectionBackend) as MockBackend;
  226. * this.backend.connections.subscribe((connection: any) => this.lastConnection = connection);
  227. * });
  228. *
  229. * it('getHeroes() should query current service url', () => {
  230. * this.heroService.getHeroes();
  231. * expect(this.lastConnection).toBeDefined('no http service connection at all?');
  232. * expect(this.lastConnection.request.url).toMatch(/api\/heroes$/, 'url invalid');
  233. * });
  234. *
  235. * it('getHeroes() should return some heroes', fakeAsync(() => {
  236. * let result: String[];
  237. * this.heroService.getHeroes().then((heroes: String[]) => result = heroes);
  238. * this.lastConnection.mockRespond(new Response(new ResponseOptions({
  239. * body: JSON.stringify({data: [HERO_ONE, HERO_TWO]}),
  240. * })));
  241. * tick();
  242. * expect(result.length).toEqual(2, 'should contain given amount of heroes');
  243. * expect(result[0]).toEqual(HERO_ONE, ' HERO_ONE should be the first hero');
  244. * expect(result[1]).toEqual(HERO_TWO, ' HERO_TWO should be the second hero');
  245. * }));
  246. *
  247. * it('getHeroes() while server is down', fakeAsync(() => {
  248. * let result: String[];
  249. * let catchedError: any;
  250. * this.heroService.getHeroes()
  251. * .then((heroes: String[]) => result = heroes)
  252. * .catch((error: any) => catchedError = error);
  253. * this.lastConnection.mockRespond(new Response(new ResponseOptions({
  254. * status: 404,
  255. * statusText: 'URL not Found',
  256. * })));
  257. * tick();
  258. * expect(result).toBeUndefined();
  259. * expect(catchedError).toBeDefined();
  260. * }));
  261. * });
  262. * ```
  263. *
  264. * This method only exists in the mock implementation, not in real Backends.
  265. *
  266. * @deprecated use \@angular/common/http instead
  267. */
  268. var MockBackend = /** @class */ (function () {
  269. function MockBackend() {
  270. var _this = this;
  271. this.connectionsArray = [];
  272. this.connections = new rxjs_Subject.Subject();
  273. this.connections.subscribe(function (connection) { return _this.connectionsArray.push(connection); });
  274. this.pendingConnections = new rxjs_Subject.Subject();
  275. }
  276. /**
  277. * Checks all connections, and raises an exception if any connection has not received a response.
  278. *
  279. * This method only exists in the mock implementation, not in real Backends.
  280. */
  281. /**
  282. * Checks all connections, and raises an exception if any connection has not received a response.
  283. *
  284. * This method only exists in the mock implementation, not in real Backends.
  285. * @return {?}
  286. */
  287. MockBackend.prototype.verifyNoPendingRequests = /**
  288. * Checks all connections, and raises an exception if any connection has not received a response.
  289. *
  290. * This method only exists in the mock implementation, not in real Backends.
  291. * @return {?}
  292. */
  293. function () {
  294. var /** @type {?} */ pending = 0;
  295. this.pendingConnections.subscribe(function (c) { return pending++; });
  296. if (pending > 0)
  297. throw new Error(pending + " pending connections to be resolved");
  298. };
  299. /**
  300. * Can be used in conjunction with `verifyNoPendingRequests` to resolve any not-yet-resolve
  301. * connections, if it's expected that there are connections that have not yet received a response.
  302. *
  303. * This method only exists in the mock implementation, not in real Backends.
  304. */
  305. /**
  306. * Can be used in conjunction with `verifyNoPendingRequests` to resolve any not-yet-resolve
  307. * connections, if it's expected that there are connections that have not yet received a response.
  308. *
  309. * This method only exists in the mock implementation, not in real Backends.
  310. * @return {?}
  311. */
  312. MockBackend.prototype.resolveAllConnections = /**
  313. * Can be used in conjunction with `verifyNoPendingRequests` to resolve any not-yet-resolve
  314. * connections, if it's expected that there are connections that have not yet received a response.
  315. *
  316. * This method only exists in the mock implementation, not in real Backends.
  317. * @return {?}
  318. */
  319. function () { this.connections.subscribe(function (c) { return c.readyState = 4; }); };
  320. /**
  321. * Creates a new {@link MockConnection}. This is equivalent to calling `new
  322. * MockConnection()`, except that it also will emit the new `Connection` to the `connections`
  323. * emitter of this `MockBackend` instance. This method will usually only be used by tests
  324. * against the framework itself, not by end-users.
  325. */
  326. /**
  327. * Creates a new {\@link MockConnection}. This is equivalent to calling `new
  328. * MockConnection()`, except that it also will emit the new `Connection` to the `connections`
  329. * emitter of this `MockBackend` instance. This method will usually only be used by tests
  330. * against the framework itself, not by end-users.
  331. * @param {?} req
  332. * @return {?}
  333. */
  334. MockBackend.prototype.createConnection = /**
  335. * Creates a new {\@link MockConnection}. This is equivalent to calling `new
  336. * MockConnection()`, except that it also will emit the new `Connection` to the `connections`
  337. * emitter of this `MockBackend` instance. This method will usually only be used by tests
  338. * against the framework itself, not by end-users.
  339. * @param {?} req
  340. * @return {?}
  341. */
  342. function (req) {
  343. if (!req || !(req instanceof _angular_http.Request)) {
  344. throw new Error("createConnection requires an instance of Request, got " + req);
  345. }
  346. var /** @type {?} */ connection = new MockConnection(req);
  347. this.connections.next(connection);
  348. return connection;
  349. };
  350. MockBackend.decorators = [
  351. { type: _angular_core.Injectable },
  352. ];
  353. /** @nocollapse */
  354. MockBackend.ctorParameters = function () { return []; };
  355. return MockBackend;
  356. }());
  357. exports.MockConnection = MockConnection;
  358. exports.MockBackend = MockBackend;
  359. Object.defineProperty(exports, '__esModule', { value: true });
  360. })));
  361. //# sourceMappingURL=http-testing.umd.js.map