UNPKG

15.8 kBSource Map (JSON)View Raw
1{"version":3,"file":"testing.js","sources":["../testing/src/resource_loader_mock.ts","../testing/src/schema_registry_mock.ts","../testing/src/directive_resolver_mock.ts","../testing/src/ng_module_resolver_mock.ts","../testing/src/pipe_resolver_mock.ts","../testing/testing.ts"],"sourcesContent":["/**\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 */\n\nimport {ResourceLoader} from '@angular/compiler';\n\n/**\n * A mock implementation of {@link ResourceLoader} that allows outgoing requests to be mocked\n * and responded to within a single test, without going to the network.\n */\nexport class MockResourceLoader extends ResourceLoader {\n private _expectations: _Expectation[] = [];\n private _definitions = new Map<string, string>();\n private _requests: _PendingRequest[] = [];\n\n get(url: string): Promise<string> {\n const request = new _PendingRequest(url);\n this._requests.push(request);\n return request.getPromise();\n }\n\n hasPendingRequests() { return !!this._requests.length; }\n\n /**\n * Add an expectation for the given URL. Incoming requests will be checked against\n * the next expectation (in FIFO order). The `verifyNoOutstandingExpectations` method\n * can be used to check if any expectations have not yet been met.\n *\n * The response given will be returned if the expectation matches.\n */\n expect(url: string, response: string) {\n const expectation = new _Expectation(url, response);\n this._expectations.push(expectation);\n }\n\n /**\n * Add a definition for the given URL to return the given response. Unlike expectations,\n * definitions have no order and will satisfy any matching request at any time. Also\n * unlike expectations, unused definitions do not cause `verifyNoOutstandingExpectations`\n * to return an error.\n */\n when(url: string, response: string) { this._definitions.set(url, response); }\n\n /**\n * Process pending requests and verify there are no outstanding expectations. Also fails\n * if no requests are pending.\n */\n flush() {\n if (this._requests.length === 0) {\n throw new Error('No pending requests to flush');\n }\n\n do {\n this._processRequest(this._requests.shift() !);\n } while (this._requests.length > 0);\n\n this.verifyNoOutstandingExpectations();\n }\n\n /**\n * Throw an exception if any expectations have not been satisfied.\n */\n verifyNoOutstandingExpectations() {\n if (this._expectations.length === 0) return;\n\n const urls: string[] = [];\n for (let i = 0; i < this._expectations.length; i++) {\n const expectation = this._expectations[i];\n urls.push(expectation.url);\n }\n\n throw new Error(`Unsatisfied requests: ${urls.join(', ')}`);\n }\n\n private _processRequest(request: _PendingRequest) {\n const url = request.url;\n\n if (this._expectations.length > 0) {\n const expectation = this._expectations[0];\n if (expectation.url == url) {\n remove(this._expectations, expectation);\n request.complete(expectation.response);\n return;\n }\n }\n\n if (this._definitions.has(url)) {\n const response = this._definitions.get(url);\n request.complete(response == null ? null : response);\n return;\n }\n\n throw new Error(`Unexpected request ${url}`);\n }\n}\n\nclass _PendingRequest {\n // TODO(issue/24571): remove '!'.\n resolve !: (result: string) => void;\n // TODO(issue/24571): remove '!'.\n reject !: (error: any) => void;\n promise: Promise<string>;\n\n constructor(public url: string) {\n this.promise = new Promise((res, rej) => {\n this.resolve = res;\n this.reject = rej;\n });\n }\n\n complete(response: string|null) {\n if (response == null) {\n this.reject(`Failed to load ${this.url}`);\n } else {\n this.resolve(response);\n }\n }\n\n getPromise(): Promise<string> { return this.promise; }\n}\n\nclass _Expectation {\n url: string;\n response: string;\n constructor(url: string, response: string) {\n this.url = url;\n this.response = response;\n }\n}\n\nfunction remove<T>(list: T[], el: T): void {\n const index = list.indexOf(el);\n if (index > -1) {\n list.splice(index, 1);\n }\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 */\n\nimport {ElementSchemaRegistry, core} from '@angular/compiler';\n\nexport class MockSchemaRegistry implements ElementSchemaRegistry {\n constructor(\n public existingProperties: {[key: string]: boolean},\n public attrPropMapping: {[key: string]: string},\n public existingElements: {[key: string]: boolean}, public invalidProperties: Array<string>,\n public invalidAttributes: Array<string>) {}\n\n hasProperty(tagName: string, property: string, schemas: core.SchemaMetadata[]): boolean {\n const value = this.existingProperties[property];\n return value === void 0 ? true : value;\n }\n\n hasElement(tagName: string, schemaMetas: core.SchemaMetadata[]): boolean {\n const value = this.existingElements[tagName.toLowerCase()];\n return value === void 0 ? true : value;\n }\n\n allKnownElementNames(): string[] { return Object.keys(this.existingElements); }\n\n securityContext(selector: string, property: string, isAttribute: boolean): core.SecurityContext {\n return core.SecurityContext.NONE;\n }\n\n getMappedPropName(attrName: string): string { return this.attrPropMapping[attrName] || attrName; }\n\n getDefaultComponentElementName(): string { return 'ng-component'; }\n\n validateProperty(name: string): {error: boolean, msg?: string} {\n if (this.invalidProperties.indexOf(name) > -1) {\n return {error: true, msg: `Binding to property '${name}' is disallowed for security reasons`};\n } else {\n return {error: false};\n }\n }\n\n validateAttribute(name: string): {error: boolean, msg?: string} {\n if (this.invalidAttributes.indexOf(name) > -1) {\n return {\n error: true,\n msg: `Binding to attribute '${name}' is disallowed for security reasons`\n };\n } else {\n return {error: false};\n }\n }\n\n normalizeAnimationStyleProperty(propName: string): string { return propName; }\n normalizeAnimationStyleValue(camelCaseProp: string, userProvidedProp: string, val: string|number):\n {error: string, value: string} {\n return {error: null !, value: val.toString()};\n }\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 {CompileReflector, DirectiveResolver, core} from '@angular/compiler';\n\n/**\n * An implementation of {@link DirectiveResolver} that allows overriding\n * various properties of directives.\n */\nexport class MockDirectiveResolver extends DirectiveResolver {\n private _directives = new Map<core.Type, core.Directive>();\n\n constructor(reflector: CompileReflector) { super(reflector); }\n\n resolve(type: core.Type): core.Directive;\n resolve(type: core.Type, throwIfNotFound: true): core.Directive;\n resolve(type: core.Type, throwIfNotFound: boolean): core.Directive|null;\n resolve(type: core.Type, throwIfNotFound = true): core.Directive|null {\n return this._directives.get(type) || super.resolve(type, throwIfNotFound);\n }\n\n /**\n * Overrides the {@link core.Directive} for a directive.\n */\n setDirective(type: core.Type, metadata: core.Directive): void {\n this._directives.set(type, metadata);\n }\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 */\n\nimport {CompileReflector, NgModuleResolver, core} from '@angular/compiler';\n\nexport class MockNgModuleResolver extends NgModuleResolver {\n private _ngModules = new Map<core.Type, core.NgModule>();\n\n constructor(reflector: CompileReflector) { super(reflector); }\n\n /**\n * Overrides the {@link NgModule} for a module.\n */\n setNgModule(type: core.Type, metadata: core.NgModule): void {\n this._ngModules.set(type, metadata);\n }\n\n /**\n * Returns the {@link NgModule} for a module:\n * - Set the {@link NgModule} to the overridden view when it exists or fallback to the\n * default\n * `NgModuleResolver`, see `setNgModule`.\n */\n resolve(type: core.Type, throwIfNotFound = true): core.NgModule {\n return this._ngModules.get(type) || super.resolve(type, throwIfNotFound) !;\n }\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 */\n\nimport {CompileReflector, PipeResolver, core} from '@angular/compiler';\n\nexport class MockPipeResolver extends PipeResolver {\n private _pipes = new Map<core.Type, core.Pipe>();\n\n constructor(refector: CompileReflector) { super(refector); }\n\n /**\n * Overrides the {@link Pipe} for a pipe.\n */\n setPipe(type: core.Type, metadata: core.Pipe): void { this._pipes.set(type, metadata); }\n\n /**\n * Returns the {@link Pipe} for a pipe:\n * - Set the {@link Pipe} to the overridden view when it exists or fallback to the\n * default\n * `PipeResolver`, see `setPipe`.\n */\n resolve(type: core.Type, throwIfNotFound = true): core.Pipe {\n let metadata = this._pipes.get(type);\n if (!metadata) {\n metadata = super.resolve(type, throwIfNotFound) !;\n }\n return metadata;\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAcA,MAAa,kBAAmB,SAAQ,cAAc;IAAtD;;QACU,kBAAa,GAAmB,EAAE,CAAC;QACnC,iBAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;QACzC,cAAS,GAAsB,EAAE,CAAC;KAiF3C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