123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 |
- /**
- * @license Angular v5.2.11
- * (c) 2010-2018 Google, Inc. https://angular.io/
- * License: MIT
- */
- import { DirectiveResolver, NgModuleResolver, PipeResolver, ResourceLoader, core } from '@angular/compiler';
-
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes} checked by tsc
- */
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- /**
- * A mock implementation of {\@link ResourceLoader} that allows outgoing requests to be mocked
- * and responded to within a single test, without going to the network.
- */
- class MockResourceLoader extends ResourceLoader {
- constructor() {
- super(...arguments);
- this._expectations = [];
- this._definitions = new Map();
- this._requests = [];
- }
- /**
- * @param {?} url
- * @return {?}
- */
- get(url) {
- const /** @type {?} */ request = new _PendingRequest(url);
- this._requests.push(request);
- return request.getPromise();
- }
- /**
- * @return {?}
- */
- hasPendingRequests() { return !!this._requests.length; }
- /**
- * Add an expectation for the given URL. Incoming requests will be checked against
- * the next expectation (in FIFO order). The `verifyNoOutstandingExpectations` method
- * can be used to check if any expectations have not yet been met.
- *
- * The response given will be returned if the expectation matches.
- * @param {?} url
- * @param {?} response
- * @return {?}
- */
- expect(url, response) {
- const /** @type {?} */ expectation = new _Expectation(url, response);
- this._expectations.push(expectation);
- }
- /**
- * Add a definition for the given URL to return the given response. Unlike expectations,
- * definitions have no order and will satisfy any matching request at any time. Also
- * unlike expectations, unused definitions do not cause `verifyNoOutstandingExpectations`
- * to return an error.
- * @param {?} url
- * @param {?} response
- * @return {?}
- */
- when(url, response) { this._definitions.set(url, response); }
- /**
- * Process pending requests and verify there are no outstanding expectations. Also fails
- * if no requests are pending.
- * @return {?}
- */
- flush() {
- if (this._requests.length === 0) {
- throw new Error('No pending requests to flush');
- }
- do {
- this._processRequest(/** @type {?} */ ((this._requests.shift())));
- } while (this._requests.length > 0);
- this.verifyNoOutstandingExpectations();
- }
- /**
- * Throw an exception if any expectations have not been satisfied.
- * @return {?}
- */
- verifyNoOutstandingExpectations() {
- if (this._expectations.length === 0)
- return;
- const /** @type {?} */ urls = [];
- for (let /** @type {?} */ i = 0; i < this._expectations.length; i++) {
- const /** @type {?} */ expectation = this._expectations[i];
- urls.push(expectation.url);
- }
- throw new Error(`Unsatisfied requests: ${urls.join(', ')}`);
- }
- /**
- * @param {?} request
- * @return {?}
- */
- _processRequest(request) {
- const /** @type {?} */ url = request.url;
- if (this._expectations.length > 0) {
- const /** @type {?} */ expectation = this._expectations[0];
- if (expectation.url == url) {
- remove(this._expectations, expectation);
- request.complete(expectation.response);
- return;
- }
- }
- if (this._definitions.has(url)) {
- const /** @type {?} */ response = this._definitions.get(url);
- request.complete(response == null ? null : response);
- return;
- }
- throw new Error(`Unexpected request ${url}`);
- }
- }
- class _PendingRequest {
- /**
- * @param {?} url
- */
- constructor(url) {
- this.url = url;
- this.promise = new Promise((res, rej) => {
- this.resolve = res;
- this.reject = rej;
- });
- }
- /**
- * @param {?} response
- * @return {?}
- */
- complete(response) {
- if (response == null) {
- this.reject(`Failed to load ${this.url}`);
- }
- else {
- this.resolve(response);
- }
- }
- /**
- * @return {?}
- */
- getPromise() { return this.promise; }
- }
- class _Expectation {
- /**
- * @param {?} url
- * @param {?} response
- */
- constructor(url, response) {
- this.url = url;
- this.response = response;
- }
- }
- /**
- * @template T
- * @param {?} list
- * @param {?} el
- * @return {?}
- */
- function remove(list, el) {
- const /** @type {?} */ index = list.indexOf(el);
- if (index > -1) {
- list.splice(index, 1);
- }
- }
-
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes} checked by tsc
- */
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- class MockSchemaRegistry {
- /**
- * @param {?} existingProperties
- * @param {?} attrPropMapping
- * @param {?} existingElements
- * @param {?} invalidProperties
- * @param {?} invalidAttributes
- */
- constructor(existingProperties, attrPropMapping, existingElements, invalidProperties, invalidAttributes) {
- this.existingProperties = existingProperties;
- this.attrPropMapping = attrPropMapping;
- this.existingElements = existingElements;
- this.invalidProperties = invalidProperties;
- this.invalidAttributes = invalidAttributes;
- }
- /**
- * @param {?} tagName
- * @param {?} property
- * @param {?} schemas
- * @return {?}
- */
- hasProperty(tagName, property, schemas) {
- const /** @type {?} */ value = this.existingProperties[property];
- return value === void 0 ? true : value;
- }
- /**
- * @param {?} tagName
- * @param {?} schemaMetas
- * @return {?}
- */
- hasElement(tagName, schemaMetas) {
- const /** @type {?} */ value = this.existingElements[tagName.toLowerCase()];
- return value === void 0 ? true : value;
- }
- /**
- * @return {?}
- */
- allKnownElementNames() { return Object.keys(this.existingElements); }
- /**
- * @param {?} selector
- * @param {?} property
- * @param {?} isAttribute
- * @return {?}
- */
- securityContext(selector, property, isAttribute) {
- return core.SecurityContext.NONE;
- }
- /**
- * @param {?} attrName
- * @return {?}
- */
- getMappedPropName(attrName) { return this.attrPropMapping[attrName] || attrName; }
- /**
- * @return {?}
- */
- getDefaultComponentElementName() { return 'ng-component'; }
- /**
- * @param {?} name
- * @return {?}
- */
- validateProperty(name) {
- if (this.invalidProperties.indexOf(name) > -1) {
- return { error: true, msg: `Binding to property '${name}' is disallowed for security reasons` };
- }
- else {
- return { error: false };
- }
- }
- /**
- * @param {?} name
- * @return {?}
- */
- validateAttribute(name) {
- if (this.invalidAttributes.indexOf(name) > -1) {
- return {
- error: true,
- msg: `Binding to attribute '${name}' is disallowed for security reasons`
- };
- }
- else {
- return { error: false };
- }
- }
- /**
- * @param {?} propName
- * @return {?}
- */
- normalizeAnimationStyleProperty(propName) { return propName; }
- /**
- * @param {?} camelCaseProp
- * @param {?} userProvidedProp
- * @param {?} val
- * @return {?}
- */
- normalizeAnimationStyleValue(camelCaseProp, userProvidedProp, val) {
- return { error: /** @type {?} */ ((null)), value: val.toString() };
- }
- }
-
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes} checked by tsc
- */
- /**
- * An implementation of {\@link DirectiveResolver} that allows overriding
- * various properties of directives.
- */
- class MockDirectiveResolver extends DirectiveResolver {
- /**
- * @param {?} reflector
- */
- constructor(reflector) {
- super(reflector);
- this._directives = new Map();
- }
- /**
- * @param {?} type
- * @param {?=} throwIfNotFound
- * @return {?}
- */
- resolve(type, throwIfNotFound = true) {
- return this._directives.get(type) || super.resolve(type, throwIfNotFound);
- }
- /**
- * Overrides the {\@link core.Directive} for a directive.
- * @param {?} type
- * @param {?} metadata
- * @return {?}
- */
- setDirective(type, metadata) {
- this._directives.set(type, metadata);
- }
- }
-
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes} checked by tsc
- */
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- class MockNgModuleResolver extends NgModuleResolver {
- /**
- * @param {?} reflector
- */
- constructor(reflector) {
- super(reflector);
- this._ngModules = new Map();
- }
- /**
- * Overrides the {\@link NgModule} for a module.
- * @param {?} type
- * @param {?} metadata
- * @return {?}
- */
- setNgModule(type, metadata) {
- this._ngModules.set(type, metadata);
- }
- /**
- * Returns the {\@link NgModule} for a module:
- * - Set the {\@link NgModule} to the overridden view when it exists or fallback to the
- * default
- * `NgModuleResolver`, see `setNgModule`.
- * @param {?} type
- * @param {?=} throwIfNotFound
- * @return {?}
- */
- resolve(type, throwIfNotFound = true) {
- return this._ngModules.get(type) || /** @type {?} */ ((super.resolve(type, throwIfNotFound)));
- }
- }
-
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes} checked by tsc
- */
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- class MockPipeResolver extends PipeResolver {
- /**
- * @param {?} refector
- */
- constructor(refector) {
- super(refector);
- this._pipes = new Map();
- }
- /**
- * Overrides the {\@link Pipe} for a pipe.
- * @param {?} type
- * @param {?} metadata
- * @return {?}
- */
- setPipe(type, metadata) { this._pipes.set(type, metadata); }
- /**
- * Returns the {\@link Pipe} for a pipe:
- * - Set the {\@link Pipe} to the overridden view when it exists or fallback to the
- * default
- * `PipeResolver`, see `setPipe`.
- * @param {?} type
- * @param {?=} throwIfNotFound
- * @return {?}
- */
- resolve(type, throwIfNotFound = true) {
- let /** @type {?} */ metadata = this._pipes.get(type);
- if (!metadata) {
- metadata = /** @type {?} */ ((super.resolve(type, throwIfNotFound)));
- }
- return metadata;
- }
- }
-
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes} checked by tsc
- */
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- /**
- * @module
- * @description
- * Entry point for all APIs of the compiler package.
- *
- * <div class="callout is-critical">
- * <header>Unstable APIs</header>
- * <p>
- * All compiler apis are currently considered experimental and private!
- * </p>
- * <p>
- * We expect the APIs in this package to keep on changing. Do not rely on them.
- * </p>
- * </div>
- */
-
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes} checked by tsc
- */
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- /**
- * @module
- * @description
- * Entry point for all public APIs of this package.
- */
-
- // This file only reexports content of the `src` folder. Keep it that way.
-
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes} checked by tsc
- */
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- // This file is not used to build this module. It is only used during editing
- // by the TypeScript language service and during build for verification. `ngc`
- // replaces this file with production index.ts when it rewrites private symbol
- // names.
-
- export { MockResourceLoader, MockSchemaRegistry, MockDirectiveResolver, MockNgModuleResolver, MockPipeResolver };
- //# sourceMappingURL=testing.js.map
|