Front end of the Slack clone application.

http-testing.umd.js.map 19KB

1
  1. {"version":3,"file":"http-testing.umd.js","sources":["../../../packages/http/esm5/testing/src/mock_backend.js"],"sourcesContent":["/**\n * @fileoverview added by tsickle\n * @suppress {checkTypes} checked by tsc\n */\n/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport { Injectable } from '@angular/core';\nimport { ReadyState, Request } from '@angular/http';\nimport { ReplaySubject } from 'rxjs/ReplaySubject';\nimport { Subject } from 'rxjs/Subject';\nimport { take } from 'rxjs/operator/take';\n/**\n *\n * Mock Connection to represent a {\\@link Connection} for tests.\n *\n * @deprecated use \\@angular/common/http instead\n */\nvar /**\n *\n * Mock Connection to represent a {\\@link Connection} for tests.\n *\n * @deprecated use \\@angular/common/http instead\n */\nMockConnection = /** @class */ (function () {\n function MockConnection(req) {\n this.response = /** @type {?} */ (take.call(new ReplaySubject(1), 1));\n this.readyState = ReadyState.Open;\n this.request = req;\n }\n /**\n * Sends a mock response to the connection. This response is the value that is emitted to the\n * {@link EventEmitter} returned by {@link Http}.\n *\n * ### Example\n *\n * ```\n * var connection;\n * backend.connections.subscribe(c => connection = c);\n * http.request('data.json').subscribe(res => console.log(res.text()));\n * connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs\n * 'fake response'\n * ```\n *\n */\n /**\n * Sends a mock response to the connection. This response is the value that is emitted to the\n * {\\@link EventEmitter} returned by {\\@link Http}.\n *\n * ### Example\n *\n * ```\n * var connection;\n * backend.connections.subscribe(c => connection = c);\n * http.request('data.json').subscribe(res => console.log(res.text()));\n * connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs\n * 'fake response'\n * ```\n *\n * @param {?} res\n * @return {?}\n */\n MockConnection.prototype.mockRespond = /**\n * Sends a mock response to the connection. This response is the value that is emitted to the\n * {\\@link EventEmitter} returned by {\\@link Http}.\n *\n * ### Example\n *\n * ```\n * var connection;\n * backend.connections.subscribe(c => connection = c);\n * http.request('data.json').subscribe(res => console.log(res.text()));\n * connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs\n * 'fake response'\n * ```\n *\n * @param {?} res\n * @return {?}\n */\n function (res) {\n if (this.readyState === ReadyState.Done || this.readyState === ReadyState.Cancelled) {\n throw new Error('Connection has already been resolved');\n }\n this.readyState = ReadyState.Done;\n this.response.next(res);\n this.response.complete();\n };\n /**\n * Not yet implemented!\n *\n * Sends the provided {@link Response} to the `downloadObserver` of the `Request`\n * associated with this connection.\n */\n /**\n * Not yet implemented!\n *\n * Sends the provided {\\@link Response} to the `downloadObserver` of the `Request`\n * associated with this connection.\n * @param {?} res\n * @return {?}\n */\n MockConnection.prototype.mockDownload = /**\n * Not yet implemented!\n *\n * Sends the provided {\\@link Response} to the `downloadObserver` of the `Request`\n * associated with this connection.\n * @param {?} res\n * @return {?}\n */\n function (res) {\n // this.request.downloadObserver.onNext(res);\n // if (res.bytesLoaded === res.totalBytes) {\n // this.request.downloadObserver.onCompleted();\n // }\n };\n // TODO(jeffbcross): consider using Response type\n /**\n * Emits the provided error object as an error to the {@link Response} {@link EventEmitter}\n * returned\n * from {@link Http}.\n *\n * ### Example\n *\n * ```\n * var connection;\n * backend.connections.subscribe(c => connection = c);\n * http.request('data.json').subscribe(res => res, err => console.log(err)));\n * connection.mockError(new Error('error'));\n * ```\n *\n */\n /**\n * Emits the provided error object as an error to the {\\@link Response} {\\@link EventEmitter}\n * returned\n * from {\\@link Http}.\n *\n * ### Example\n *\n * ```\n * var connection;\n * backend.connections.subscribe(c => connection = c);\n * http.request('data.json').subscribe(res => res, err => console.log(err)));\n * connection.mockError(new Error('error'));\n * ```\n *\n * @param {?=} err\n * @return {?}\n */\n MockConnection.prototype.mockError = /**\n * Emits the provided error object as an error to the {\\@link Response} {\\@link EventEmitter}\n * returned\n * from {\\@link Http}.\n *\n * ### Example\n *\n * ```\n * var connection;\n * backend.connections.subscribe(c => connection = c);\n * http.request('data.json').subscribe(res => res, err => console.log(err)));\n * connection.mockError(new Error('error'));\n * ```\n *\n * @param {?=} err\n * @return {?}\n */\n function (err) {\n // Matches ResourceLoader semantics\n this.readyState = ReadyState.Done;\n this.response.error(err);\n };\n return MockConnection;\n}());\n/**\n *\n * Mock Connection to represent a {\\@link Connection} for tests.\n *\n * @deprecated use \\@angular/common/http instead\n */\nexport { MockConnection };\nfunction MockConnection_tsickle_Closure_declarations() {\n /**\n * Describes the state of the connection, based on `XMLHttpRequest.readyState`, but with\n * additional states. For example, state 5 indicates an aborted connection.\n * @type {?}\n */\n MockConnection.prototype.readyState;\n /**\n * {\\@link Request} instance used to create the connection.\n * @type {?}\n */\n MockConnection.prototype.request;\n /**\n * {\\@link EventEmitter} of {\\@link Response}. Can be subscribed to in order to be notified when a\n * response is available.\n * @type {?}\n */\n MockConnection.prototype.response;\n}\n/**\n * A mock backend for testing the {\\@link Http} service.\n *\n * This class can be injected in tests, and should be used to override providers\n * to other backends, such as {\\@link XHRBackend}.\n *\n * ### Example\n *\n * ```\n * import {Injectable, Injector} from '\\@angular/core';\n * import {async, fakeAsync, tick} from '\\@angular/core/testing';\n * import {BaseRequestOptions, ConnectionBackend, Http, RequestOptions} from '\\@angular/http';\n * import {Response, ResponseOptions} from '\\@angular/http';\n * import {MockBackend, MockConnection} from '\\@angular/http/testing';\n *\n * const HERO_ONE = 'HeroNrOne';\n * const HERO_TWO = 'WillBeAlwaysTheSecond';\n *\n * \\@Injectable()\n * class HeroService {\n * constructor(private http: Http) {}\n *\n * getHeroes(): Promise<String[]> {\n * return this.http.get('myservices.de/api/heroes')\n * .toPromise()\n * .then(response => response.json().data)\n * .catch(e => this.handleError(e));\n * }\n *\n * private handleError(error: any): Promise<any> {\n * console.error('An error occurred', error);\n * return Promise.reject(error.message || error);\n * }\n * }\n *\n * describe('MockBackend HeroService Example', () => {\n * beforeEach(() => {\n * this.injector = Injector.create([\n * {provide: ConnectionBackend, useClass: MockBackend},\n * {provide: RequestOptions, useClass: BaseRequestOptions},\n * Http,\n * HeroService,\n * ]);\n * this.heroService = this.injector.get(HeroService);\n * this.backend = this.injector.get(ConnectionBackend) as MockBackend;\n * this.backend.connections.subscribe((connection: any) => this.lastConnection = connection);\n * });\n *\n * it('getHeroes() should query current service url', () => {\n * this.heroService.getHeroes();\n * expect(this.lastConnection).toBeDefined('no http service connection at all?');\n * expect(this.lastConnection.request.url).toMatch(/api\\/heroes$/, 'url invalid');\n * });\n *\n * it('getHeroes() should return some heroes', fakeAsync(() => {\n * let result: String[];\n * this.heroService.getHeroes().then((heroes: String[]) => result = heroes);\n * this.lastConnection.mockRespond(new Response(new ResponseOptions({\n * body: JSON.stringify({data: [HERO_ONE, HERO_TWO]}),\n * })));\n * tick();\n * expect(result.length).toEqual(2, 'should contain given amount of heroes');\n * expect(result[0]).toEqual(HERO_ONE, ' HERO_ONE should be the first hero');\n * expect(result[1]).toEqual(HERO_TWO, ' HERO_TWO should be the second hero');\n * }));\n *\n * it('getHeroes() while server is down', fakeAsync(() => {\n * let result: String[];\n * let catchedError: any;\n * this.heroService.getHeroes()\n * .then((heroes: String[]) => result = heroes)\n * .catch((error: any) => catchedError = error);\n * this.lastConnection.mockRespond(new Response(new ResponseOptions({\n * status: 404,\n * statusText: 'URL not Found',\n * })));\n * tick();\n * expect(result).toBeUndefined();\n * expect(catchedError).toBeDefined();\n * }));\n * });\n * ```\n *\n * This method only exists in the mock implementation, not in real Backends.\n *\n * @deprecated use \\@angular/common/http instead\n */\nvar MockBackend = /** @class */ (function () {\n function MockBackend() {\n var _this = this;\n this.connectionsArray = [];\n this.connections = new Subject();\n this.connections.subscribe(function (connection) { return _this.connectionsArray.push(connection); });\n this.pendingConnections = new Subject();\n }\n /**\n * Checks all connections, and raises an exception if any connection has not received a response.\n *\n * This method only exists in the mock implementation, not in real Backends.\n */\n /**\n * Checks all connections, and raises an exception if any connection has not received a response.\n *\n * This method only exists in the mock implementation, not in real Backends.\n * @return {?}\n */\n MockBackend.prototype.verifyNoPendingRequests = /**\n * Checks all connections, and raises an exception if any connection has not received a response.\n *\n * This method only exists in the mock implementation, not in real Backends.\n * @return {?}\n */\n function () {\n var /** @type {?} */ pending = 0;\n this.pendingConnections.subscribe(function (c) { return pending++; });\n if (pending > 0)\n throw new Error(pending + \" pending connections to be resolved\");\n };\n /**\n * Can be used in conjunction with `verifyNoPendingRequests` to resolve any not-yet-resolve\n * connections, if it's expected that there are connections that have not yet received a response.\n *\n * This method only exists in the mock implementation, not in real Backends.\n */\n /**\n * Can be used in conjunction with `verifyNoPendingRequests` to resolve any not-yet-resolve\n * connections, if it's expected that there are connections that have not yet received a response.\n *\n * This method only exists in the mock implementation, not in real Backends.\n * @return {?}\n */\n MockBackend.prototype.resolveAllConnections = /**\n * Can be used in conjunction with `verifyNoPendingRequests` to resolve any not-yet-resolve\n * connections, if it's expected that there are connections that have not yet received a response.\n *\n * This method only exists in the mock implementation, not in real Backends.\n * @return {?}\n */\n function () { this.connections.subscribe(function (c) { return c.readyState = 4; }); };\n /**\n * Creates a new {@link MockConnection}. This is equivalent to calling `new\n * MockConnection()`, except that it also will emit the new `Connection` to the `connections`\n * emitter of this `MockBackend` instance. This method will usually only be used by tests\n * against the framework itself, not by end-users.\n */\n /**\n * Creates a new {\\@link MockConnection}. This is equivalent to calling `new\n * MockConnection()`, except that it also will emit the new `Connection` to the `connections`\n * emitter of this `MockBackend` instance. This method will usually only be used by tests\n * against the framework itself, not by end-users.\n * @param {?} req\n * @return {?}\n */\n MockBackend.prototype.createConnection = /**\n * Creates a new {\\@link MockConnection}. This is equivalent to calling `new\n * MockConnection()`, except that it also will emit the new `Connection` to the `connections`\n * emitter of this `MockBackend` instance. This method will usually only be used by tests\n * against the framework itself, not by end-users.\n * @param {?} req\n * @return {?}\n */\n function (req) {\n if (!req || !(req instanceof Request)) {\n throw new Error(\"createConnection requires an instance of Request, got \" + req);\n }\n var /** @type {?} */ connection = new MockConnection(req);\n this.connections.next(connection);\n return connection;\n };\n MockBackend.decorators = [\n { type: Injectable },\n ];\n /** @nocollapse */\n MockBackend.ctorParameters = function () { return []; };\n return MockBackend;\n}());\nexport { MockBackend };\nfunction MockBackend_tsickle_Closure_declarations() {\n /** @type {!Array<{type: !Function, args: (undefined|!Array<?>)}>} */\n MockBackend.decorators;\n /**\n * @nocollapse\n * @type {function(): !Array<(null|{type: ?, decorators: (undefined|!Array<{type: !Function, args: (undefined|!Array<?>)}>)})>}\n */\n MockBackend.ctorParameters;\n /**\n * {\\@link EventEmitter}\n * of {\\@link MockConnection} instances that have been created by this backend. Can be subscribed\n * to in order to respond to connections.\n *\n * ### Example\n *\n * ```\n * import {Injector} from '\\@angular/core';\n * import {fakeAsync, tick} from '\\@angular/core/testing';\n * import {BaseRequestOptions, ConnectionBackend, Http, RequestOptions} from '\\@angular/http';\n * import {Response, ResponseOptions} from '\\@angular/http';\n * import {MockBackend, MockConnection} from '\\@angular/http/testing';\n *\n * it('should get a response', fakeAsync(() => {\n * let connection:\n * MockConnection; // this will be set when a new connection is emitted from the\n * // backend.\n * let text: string; // this will be set from mock response\n * let injector = Injector.create([\n * {provide: ConnectionBackend, useClass: MockBackend},\n * {provide: RequestOptions, useClass: BaseRequestOptions},\n * Http,\n * ]);\n * let backend = injector.get(ConnectionBackend);\n * let http = injector.get(Http);\n * backend.connections.subscribe((c: MockConnection) => connection = c);\n * http.request('something.json').toPromise().then((res: any) => text = res.text());\n * connection.mockRespond(new Response(new ResponseOptions({body: 'Something'})));\n * tick();\n * expect(text).toBe('Something');\n * }));\n * ```\n *\n * This property only exists in the mock implementation, not in real Backends.\n * @type {?}\n */\n MockBackend.prototype.connections;\n /**\n * An array representation of `connections`. This array will be updated with each connection that\n * is created by this backend.\n *\n * This property only exists in the mock implementation, not in real Backends.\n * @type {?}\n */\n MockBackend.prototype.connectionsArray;\n /**\n * {\\@link EventEmitter} of {\\@link MockConnection} instances that haven't yet been resolved (i.e.\n * with a `readyState`\n * less than 4). Used internally to verify that no connections are pending via the\n * `verifyNoPendingRequests` method.\n *\n * This property only exists in the mock implementation, not in real Backends.\n * @type {?}\n */\n MockBackend.prototype.pendingConnections;\n}\n//# sourceMappingURL=mock_backend.js.map"],"names":["take","ReplaySubject","ReadyState","Subject","Request","Injectable"],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;AAsBA,IAMA,cAAc,kBAAkB,YAAY;IACxC,SAAS,cAAc,CAAC,GAAG,EAAE;QACzB,IAAI,CAAC,QAAQ,qBAAqBA,uBAAI,CAAC,IAAI,CAAC,IAAIC,gCAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACtE,IAAI,CAAC,UAAU,GAAGC,wBAAU,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;KACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAiCD,cAAc,CAAC,SAAS,CAAC,WAAW;;;;;;;;;;;;;;;;;IAiBpC,UAAU,GAAG,EAAE;QACX,IAAI,IAAI,CAAC,UAAU,KAAKA,wBAAU,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,KAAKA,wBAAU,CAAC,SAAS,EAAE;YACjF,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;SAC3D;QACD,IAAI,CAAC,UAAU,GAAGA,wBAAU,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;KAC5B,CAAC;;;;;;;;;;;;;;;IAeF,cAAc,CAAC,SAAS,CAAC,YAAY;;;;;;;;IAQrC,UAAU,GAAG,EAAE;;;;;KAKd,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkCF,cAAc,CAAC,SAAS,CAAC,SAAS;;;;;;;;;;;;;;;;;IAiBlC,UAAU,GAAG,EAAE;;QAEX,IAAI,CAAC,UAAU,GAAGA,wBAA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